1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00

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

Joi validator update to accommodate 'createdAt' and 'updatedAt'
This commit is contained in:
Rory Powell 2022-06-14 13:56:42 +01:00 committed by GitHub
commit f96df1a174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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