Always return when table exists

This commit is contained in:
Adria Navarro 2024-07-11 11:06:36 +02:00
parent c565e35b53
commit 2d8361d6fd
3 changed files with 23 additions and 3 deletions

View File

@ -17,8 +17,15 @@ async function getTable(ctx: Ctx) {
export async function find(ctx: Ctx<void, RowActionsResponse>) {
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,

View File

@ -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: [],
})
)
})
})
})

View File

@ -28,3 +28,10 @@ export async function get(tableId: string) {
const rowActionsId = generateRowActionsID(tableId)
return await db.get<TableRowActions>(rowActionsId)
}
export async function docExists(tableId: string) {
const db = context.getAppDB()
const rowActionsId = generateRowActionsID(tableId)
const result = await db.exists(rowActionsId)
return result
}