1
0
Fork 0
mirror of synced 2024-06-14 00:14:39 +12:00

Joi validator update to accomodate 'createdAt' and 'updatedAt' in the schema as optional

This commit is contained in:
Dean 2022-06-14 12:34:15 +01:00
parent 1eb10890b4
commit 10157cf5ff

View file

@ -1,3 +1,5 @@
const Joi = require("joi")
function validate(schema, property) {
// Return a Koa middleware function
return (ctx, next) => {
@ -10,6 +12,12 @@ function validate(schema, property) {
} else if (ctx.request[property] != null) {
params = ctx.request[property]
}
schema = schema.append({
createdAt: Joi.any().optional(),
updatedAt: Joi.any().optional(),
})
const { error } = schema.validate(params)
if (error) {
ctx.throw(400, `Invalid ${property} - ${error.message}`)