Use validation
This commit is contained in:
parent
eea9eade5c
commit
d1a69a6660
|
@ -5,6 +5,8 @@ import { paramResource, paramSubResource } from "../../middleware/resourceId"
|
|||
import { permissions } from "@budibase/backend-core"
|
||||
import { internalSearchValidator } from "./utils/validators"
|
||||
import trimViewRowInfo from "../../middleware/trimViewRowInfo"
|
||||
import { validateBody } from "../../middleware/zod-validator"
|
||||
import { searchRowRequestValidator } from "@budibase/types"
|
||||
|
||||
const { PermissionType, PermissionLevel } = permissions
|
||||
|
||||
|
@ -32,6 +34,7 @@ router
|
|||
.post(
|
||||
"/api/:sourceId/search",
|
||||
internalSearchValidator(),
|
||||
validateBody(searchRowRequestValidator),
|
||||
paramResource("sourceId"),
|
||||
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
||||
rowController.search
|
||||
|
|
|
@ -30,6 +30,6 @@ export function validateBody(schema: AnyZodObject) {
|
|||
return validate(schema, "body")
|
||||
}
|
||||
|
||||
// export function validateParams(schema: Joi.Schema) {
|
||||
// export function validateParams(schema: AnyZodObject) {
|
||||
// return validate(schema, "params")
|
||||
// }
|
||||
|
|
|
@ -15,7 +15,6 @@ export interface PatchRowRequest extends Row {
|
|||
export interface PatchRowResponse extends Row {}
|
||||
|
||||
const searchRowRequest = z.object({
|
||||
table: z.string(),
|
||||
query: z.object({
|
||||
allOr: z.boolean().optional(),
|
||||
}),
|
||||
|
@ -36,6 +35,7 @@ const searchRowRequest = z.object({
|
|||
// indexer?: () => Promise<any>
|
||||
// rows?: Row[]
|
||||
})
|
||||
export const searchRowRequestValidator = searchRowRequest
|
||||
export type SearchRowRequest = z.infer<typeof searchRowRequest>
|
||||
|
||||
export interface SearchViewRowRequest
|
||||
|
|
Loading…
Reference in New Issue