Use validation

This commit is contained in:
Adria Navarro 2024-10-10 11:40:29 +02:00
parent eea9eade5c
commit d1a69a6660
3 changed files with 5 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import { paramResource, paramSubResource } from "../../middleware/resourceId"
import { permissions } from "@budibase/backend-core" import { permissions } from "@budibase/backend-core"
import { internalSearchValidator } from "./utils/validators" import { internalSearchValidator } from "./utils/validators"
import trimViewRowInfo from "../../middleware/trimViewRowInfo" import trimViewRowInfo from "../../middleware/trimViewRowInfo"
import { validateBody } from "../../middleware/zod-validator"
import { searchRowRequestValidator } from "@budibase/types"
const { PermissionType, PermissionLevel } = permissions const { PermissionType, PermissionLevel } = permissions
@ -32,6 +34,7 @@ router
.post( .post(
"/api/:sourceId/search", "/api/:sourceId/search",
internalSearchValidator(), internalSearchValidator(),
validateBody(searchRowRequestValidator),
paramResource("sourceId"), paramResource("sourceId"),
authorized(PermissionType.TABLE, PermissionLevel.READ), authorized(PermissionType.TABLE, PermissionLevel.READ),
rowController.search rowController.search

View File

@ -30,6 +30,6 @@ export function validateBody(schema: AnyZodObject) {
return validate(schema, "body") return validate(schema, "body")
} }
// export function validateParams(schema: Joi.Schema) { // export function validateParams(schema: AnyZodObject) {
// return validate(schema, "params") // return validate(schema, "params")
// } // }

View File

@ -15,7 +15,6 @@ export interface PatchRowRequest extends Row {
export interface PatchRowResponse extends Row {} export interface PatchRowResponse extends Row {}
const searchRowRequest = z.object({ const searchRowRequest = z.object({
table: z.string(),
query: z.object({ query: z.object({
allOr: z.boolean().optional(), allOr: z.boolean().optional(),
}), }),
@ -36,6 +35,7 @@ const searchRowRequest = z.object({
// indexer?: () => Promise<any> // indexer?: () => Promise<any>
// rows?: Row[] // rows?: Row[]
}) })
export const searchRowRequestValidator = searchRowRequest
export type SearchRowRequest = z.infer<typeof searchRowRequest> export type SearchRowRequest = z.infer<typeof searchRowRequest>
export interface SearchViewRowRequest export interface SearchViewRowRequest