diff --git a/packages/server/src/api/controllers/rowAction/crud.ts b/packages/server/src/api/controllers/rowAction/crud.ts index e58a3030fc..b54a4966bf 100644 --- a/packages/server/src/api/controllers/rowAction/crud.ts +++ b/packages/server/src/api/controllers/rowAction/crud.ts @@ -17,8 +17,15 @@ async function getTable(ctx: Ctx) { export async function find(ctx: Ctx) { const table = await getTable(ctx) - const actions = await sdk.rowActions.get(table._id!) + if (!(await sdk.rowActions.docExists(table._id!))) { + ctx.body = { + tableId: table._id!, + actions: [], + } + return + } + const actions = await sdk.rowActions.get(table._id!) ctx.body = { tableId: table._id!, ...actions, diff --git a/packages/server/src/api/routes/tests/rowAction.spec.ts b/packages/server/src/api/routes/tests/rowAction.spec.ts index cec0410282..b2f322c01f 100644 --- a/packages/server/src/api/routes/tests/rowAction.spec.ts +++ b/packages/server/src/api/routes/tests/rowAction.spec.ts @@ -183,8 +183,14 @@ describe("/rowsActions", () => { ) }) - it("returns 404 for tables without row actions", async () => { - await config.api.rowAction.find(tableId, { status: 404 }) + it("returns empty for tables without row actions", async () => { + const response = await config.api.rowAction.find(tableId) + expect(response).toEqual( + expect.objectContaining({ + tableId, + actions: [], + }) + ) }) }) }) diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index bfc4155289..6d1a98d052 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -28,3 +28,10 @@ export async function get(tableId: string) { const rowActionsId = generateRowActionsID(tableId) return await db.get(rowActionsId) } + +export async function docExists(tableId: string) { + const db = context.getAppDB() + const rowActionsId = generateRowActionsID(tableId) + const result = await db.exists(rowActionsId) + return result +}