Browse Source

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

pull/6304/head
Dean 4 years ago
parent
commit
10157cf5ff
  1. 8
      packages/server/src/middleware/joi-validator.js

8
packages/server/src/middleware/joi-validator.js

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

Loading…
Cancel
Save