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
This commit is contained in:
Andrew Rumble
2025-08-21 13:45:11 +01:00
committed by Copybot
parent 3354300e63
commit e2716298cb

View File

@@ -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 }