UNPKG

@nova-ts/core

Version:

A serverside framework used to build scalable application

33 lines (31 loc) 839 B
import { ConfigLoader } from "./chunk-VUR3D4HI.js"; import { createParameterDecorator } from "./chunk-U74ZPA45.js"; // src/Decorators/RequestBody.ts import { plainToInstance } from "class-transformer"; import { validateSync } from "class-validator"; function RequestBody() { return createParameterDecorator((req, res, next, type) => { const body = req.body; if (type) { const transformed = plainToInstance(type, body); if (ConfigLoader.get("nova.class.validate", false)) { const errors = validateSync(transformed); if (errors.length) { console.error(errors); throw new Error("Validation error occured"); } return transformed; } return transformed; } return body; }); } export { RequestBody }; //# sourceMappingURL=chunk-JBBSYXKY.js.map