Merge pull request #6304 from Budibase/fix/joi-validation
Joi validator update to accommodate 'createdAt' and 'updatedAt'
This commit is contained in:
commit
f96df1a174
|
@ -1,3 +1,5 @@
|
||||||
|
const Joi = require("joi")
|
||||||
|
|
||||||
function validate(schema, property) {
|
function validate(schema, property) {
|
||||||
// Return a Koa middleware function
|
// Return a Koa middleware function
|
||||||
return (ctx, next) => {
|
return (ctx, next) => {
|
||||||
|
@ -10,6 +12,12 @@ function validate(schema, property) {
|
||||||
} else if (ctx.request[property] != null) {
|
} else if (ctx.request[property] != null) {
|
||||||
params = ctx.request[property]
|
params = ctx.request[property]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
schema = schema.append({
|
||||||
|
createdAt: Joi.any().optional(),
|
||||||
|
updatedAt: Joi.any().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
const { error } = schema.validate(params)
|
const { error } = schema.validate(params)
|
||||||
if (error) {
|
if (error) {
|
||||||
ctx.throw(400, `Invalid ${property} - ${error.message}`)
|
ctx.throw(400, `Invalid ${property} - ${error.message}`)
|
||||||
|
|
Loading…
Reference in New Issue