From e2716298cbe892e871e29fef88140c3298e2ed48 Mon Sep 17 00:00:00 2001 From: Andrew Rumble Date: Thu, 21 Aug 2025 13:45:11 +0100 Subject: [PATCH] Add zod helpers to Validation module Co-authored-by: Eric Mc Sween <5454374+emcsween@users.noreply.github.com> Borrowed from a different commit in em-zod GitOrigin-RevId: bb6ba6f3db35964e95d0b7f44454c4aa19d15b28 --- services/web/app/src/infrastructure/Validation.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/infrastructure/Validation.js b/services/web/app/src/infrastructure/Validation.js index 672978e546..8c518d7f66 100644 --- a/services/web/app/src/infrastructure/Validation.js +++ b/services/web/app/src/infrastructure/Validation.js @@ -3,6 +3,7 @@ const { Joi: CelebrateJoi, celebrate, errors } = require('celebrate') const { ObjectId } = require('mongodb-legacy') const { NotFoundError } = require('../Features/Errors/Errors') +const { z } = require('zod') /** * @import { ZodType } from 'zod' @@ -39,6 +40,11 @@ function validate(schema) { return celebrate(schema, { allowUnknown: true }) } +const zz = { + objectId: () => + z.string().refine(ObjectId.isValid, { message: 'invalid Mongo ObjectId' }), +} + /** * Validate a request against a zod schema * @@ -59,4 +65,4 @@ function validateReq(req, schema) { } } -module.exports = { Joi, validate, errorMiddleware, validateReq } +module.exports = { Joi, validate, errorMiddleware, validateReq, z, zz }