mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
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:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user