mirror of
https://github.com/andwati/order-service.git
synced 2026-10-24 04:52:15 +00:00
17 lines
379 B
TypeScript
17 lines
379 B
TypeScript
import { ZodSchema } from "zod";
|
|
import { Request, Response, NextFunction } from "express";
|
|
|
|
export const validate =
|
|
(schema: ZodSchema) => (req: Request, _res: Response, next: NextFunction) => {
|
|
try {
|
|
schema.parse({
|
|
body: req.body,
|
|
params: req.params,
|
|
query: req.query,
|
|
});
|
|
next();
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
};
|