1. Tailwind migretion. 2. Backend Type Safety. 3. Context Refactoring.
This commit is contained in:
15
server/src/middleware/validate.ts
Normal file
15
server/src/middleware/validate.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { ZodSchema } from 'zod';
|
||||
|
||||
export const validate = (schema: ZodSchema<any>) => async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
await schema.parseAsync({
|
||||
body: req.body,
|
||||
query: req.query,
|
||||
params: req.params,
|
||||
});
|
||||
return next();
|
||||
} catch (error) {
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user