From d1a69a66607e43ca7ec80c308f474deef65de8d8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 10 Oct 2024 11:40:29 +0200 Subject: [PATCH] Use validation --- packages/server/src/api/routes/row.ts | 3 +++ packages/server/src/middleware/zod-validator.ts | 2 +- packages/types/src/api/web/app/rows.ts | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/row.ts b/packages/server/src/api/routes/row.ts index e443b2daeb..fc09b8c81d 100644 --- a/packages/server/src/api/routes/row.ts +++ b/packages/server/src/api/routes/row.ts @@ -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 diff --git a/packages/server/src/middleware/zod-validator.ts b/packages/server/src/middleware/zod-validator.ts index 7b51d908c1..6611efbeb1 100644 --- a/packages/server/src/middleware/zod-validator.ts +++ b/packages/server/src/middleware/zod-validator.ts @@ -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") // } diff --git a/packages/types/src/api/web/app/rows.ts b/packages/types/src/api/web/app/rows.ts index 166c6965c4..e696430eb4 100644 --- a/packages/types/src/api/web/app/rows.ts +++ b/packages/types/src/api/web/app/rows.ts @@ -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 // rows?: Row[] }) +export const searchRowRequestValidator = searchRowRequest export type SearchRowRequest = z.infer export interface SearchViewRowRequest