Added middleware to handle empty strings as null
This commit is contained in:
		| @@ -9,10 +9,19 @@ import storageLocationRoute from './storageLocations.js'; | ||||
|  | ||||
| import search_routes from './search/index.js'; | ||||
|  | ||||
|  | ||||
| // Router base is '/api/v1' | ||||
| 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('/categories').get(categoryRoute.get).post(categoryRoute.post).patch(categoryRoute.patch).delete(categoryRoute.del); | ||||
| // TODO: Migrate routes to lowercase. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user