1
0
Fork 0
mirror of synced 2024-10-01 09:38:55 +13:00
budibase/packages/server/src/middleware/joi-validator.js

17 lines
368 B
JavaScript
Raw Normal View History

function validate(schema, property) {
// Return a Koa middleware function
return (ctx, next) => {
if (schema) {
const { error } = schema.validate(ctx[property])
if (error) {
ctx.throw(400, `Invalid ${property} - ${error.message}`)
}
}
return next()
}
}
module.exports.body = schema => {
return validate(schema, "body")
}