Browse Source

Merge pull request #6304 from Budibase/fix/joi-validation

Joi validator update to accommodate 'createdAt' and 'updatedAt'
master
Rory Powell 4 years ago
committed by GitHub
parent
commit
f96df1a174
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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