1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-12-09 20:04:11 +01:00
unleash.unleash/src/lib/middleware/id-number-middleware.ts
Jaanus Sellin 023e1594e9
feat: validate that id is number or we throw our our source code (#6860)
Previously, we were not validating that the ID was a number, which
sometimes resulted in returning our database queries (source code) to
the frontend. Now, we have validation middleware.
2024-04-16 15:48:57 +03:00

17 lines
412 B
TypeScript

import { BadDataError } from '../error';
const idNumberMiddleware = (): any => {
return async (req, res, next) => {
const { id } = req.params;
if (!Number.isInteger(Number(id))) {
res.status(400).send(
new BadDataError('ID should be an integer').toJSON(),
);
return;
}
next();
};
};
export default idNumberMiddleware;