Added middleware to handle empty strings as null

This commit is contained in:
Leon Meier 2023-06-27 23:42:29 +02:00
parent ad84e6a3a0
commit a4d697265b

View File

@ -9,10 +9,19 @@ import storageLocationRoute from './storageLocations.js';
import search_routes from './search/index.js'; import search_routes from './search/index.js';
// Router base is '/api/v1' // Router base is '/api/v1'
const Router = express.Router({ strict: false }); const Router = express.Router({ strict: false });
// All empty strings are null values.
Router.use('*', function (req, res, next) {
for (let key in req.body) {
if (req.body[key] === '') {
req.body[key] = null;
}
}
next();
});
Router.route('/items').get(itemRoute.get).post(itemRoute.post).patch(itemRoute.patch).delete(itemRoute.del); Router.route('/items').get(itemRoute.get).post(itemRoute.post).patch(itemRoute.patch).delete(itemRoute.del);
Router.route('/categories').get(categoryRoute.get).post(categoryRoute.post).patch(categoryRoute.patch).delete(categoryRoute.del); Router.route('/categories').get(categoryRoute.get).post(categoryRoute.post).patch(categoryRoute.patch).delete(categoryRoute.del);
// TODO: Migrate routes to lowercase. // TODO: Migrate routes to lowercase.