diff --git a/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts b/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts index 888e22ef0a..aba6817e5c 100644 --- a/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts +++ b/packages/server/src/middleware/tests/trimViewRowInfo.spec.ts @@ -160,4 +160,15 @@ describe("trimViewRowInfo middleware", () => { expect(config.throw).toBeCalledTimes(1) expect(config.throw).toBeCalledWith(400, "_viewId is required") }) + + it("it should throw an error if no viewid is provided on the parameters", async () => { + const data = getRandomData() + await config.executeMiddleware(undefined as any, { + _viewId: viewId, + ...data, + }) + + expect(config.throw).toBeCalledTimes(1) + expect(config.throw).toBeCalledWith(400, "viewId path is required") + }) }) diff --git a/packages/server/src/middleware/trimViewRowInfo.ts b/packages/server/src/middleware/trimViewRowInfo.ts index 5dbe7a6da0..2e3ded27f5 100644 --- a/packages/server/src/middleware/trimViewRowInfo.ts +++ b/packages/server/src/middleware/trimViewRowInfo.ts @@ -8,7 +8,11 @@ export default async (ctx: Ctx, next: Next) => { const { body } = ctx.request const { _viewId: viewId } = body if (!viewId) { - ctx.throw(400, "_viewId is required") + return ctx.throw(400, "_viewId is required") + } + + if (!ctx.params.viewId) { + return ctx.throw(400, "viewId path is required") } const { tableId } = utils.extractViewInfoFromID(ctx.params.viewId)