MCPcopy Create free account
hub / github.com/TomDoesTech/REST-API-Tutorial / validate

Function validate

src/middleware/validateRequest.ts:5–22  ·  view source on GitHub ↗
(schema: AnySchema)

Source from the content-addressed store, hash-verified

3import log from "../logger";
4
5const validate = (schema: AnySchema) => async (
6 req: Request,
7 res: Response,
8 next: NextFunction
9) => {
10 try {
11 await schema.validate({
12 body: req.body,
13 query: req.query,
14 params: req.params,
15 });
16
17 return next();
18 } catch (e) {
19 log.error(e);
20 return res.status(400).send(e.errors);
21 }
22};
23
24export default validate;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected