UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

18 lines (15 loc) 528 B
import z from 'zod'; const validate = (schema) => (req, res, next) => { const result = schema.safeParse(req.body); if (result.success) { return next(); } const errors = Object.entries(z.flattenError(result.error).fieldErrors).map(([fieldName, err]) => ({ href: `#${fieldName}`, text: Array.isArray(err) ? err[0] : err, })); req.flash(`DPR_ERRORS`, JSON.stringify(errors)); return res.redirect(`${req.baseUrl}#`); }; export { validate }; //# sourceMappingURL=validate.js.map