/[sudobot]/branches/5.x/src/api/middleware/ValidateMiddleware.ts
ViewVC logotype

Contents of /branches/5.x/src/api/middleware/ValidateMiddleware.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 501 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { NextFunction, Response } from "express";
2 import { ZodSchema } from "zod";
3 import { log } from "../../utils/logger";
4 import Request from "../Request";
5
6 export default async function ValidateMiddleware(schema: ZodSchema, request: Request, response: Response, next: NextFunction) {
7 try {
8 const parsedBody = await schema.parseAsync(request.body);
9 request.parsedBody = parsedBody;
10 next();
11 } catch (e) {
12 log(e);
13 response.status(400).json(e);
14 }
15 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26