Clean code

This commit is contained in:
Adria Navarro 2024-02-22 13:55:26 +01:00
parent 1096b8c7f0
commit fb1bfbdae8
1 changed files with 3 additions and 4 deletions

View File

@ -1,12 +1,12 @@
import Joi, { ObjectSchema } from "joi"
import { BBContext } from "@budibase/types"
import Joi from "joi"
import { Ctx } from "@budibase/types"
function validate(
schema: Joi.ObjectSchema | Joi.ArraySchema,
property: string
) {
// Return a Koa middleware function
return (ctx: BBContext, next: any) => {
return (ctx: Ctx, next: any) => {
if (!schema) {
return next()
}
@ -30,7 +30,6 @@ function validate(
const { error } = schema.validate(params)
if (error) {
ctx.throw(400, `Invalid ${property} - ${error.message}`)
return
}
return next()
}