From 6685ebaa7b80cf0e1cee47cb85999e55b31602f3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 11 Jun 2021 19:54:47 +0100 Subject: [PATCH] Fixing bulk deletion. --- .../src/components/backend/DataTable/Table.svelte | 3 +-- .../backend/DataTable/buttons/DeleteRowsButton.svelte | 2 +- packages/server/src/api/controllers/row/internal.js | 10 +++++----- packages/server/src/api/routes/row.js | 4 ++-- packages/server/src/automations/steps/deleteRow.js | 8 ++++++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 5beef42d90..d17dc78c9f 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -74,9 +74,8 @@ } const deleteRows = async () => { - await api.post(`/api/${tableId}/rows`, { + await api.delete(`/api/${tableId}/rows`, { rows: selectedRows, - type: "delete", }) data = data.filter(row => !selectedRows.includes(row)) notifications.success(`Successfully deleted ${selectedRows.length} rows`) diff --git a/packages/builder/src/components/backend/DataTable/buttons/DeleteRowsButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/DeleteRowsButton.svelte index c17b7e82df..0b4ef1ed83 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/DeleteRowsButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/DeleteRowsButton.svelte @@ -9,7 +9,7 @@ async function confirmDeletion() { await deleteRows() - modal.hide() + modal?.hide() } diff --git a/packages/server/src/api/controllers/row/internal.js b/packages/server/src/api/controllers/row/internal.js index 027f02a5a3..8d27d9850e 100644 --- a/packages/server/src/api/controllers/row/internal.js +++ b/packages/server/src/api/controllers/row/internal.js @@ -142,8 +142,7 @@ exports.fetchView = async (ctx) => { // if this is a table view being looked for just transfer to that if (viewName.startsWith(TABLE_VIEW_BEGINS_WITH)) { ctx.params.tableId = viewName.substring(4) - await exports.fetchTableRows(ctx) - return + return exports.fetchTableRows(ctx) } const db = new CouchDB(appId) @@ -228,7 +227,8 @@ exports.find = async (ctx) => { exports.destroy = async function (ctx) { const appId = ctx.appId const db = new CouchDB(appId) - const row = await db.get(ctx.params.rowId) + const { rowId, revId } = ctx.request.body + const row = await db.get(rowId) if (row.tableId !== ctx.params.tableId) { throw "Supplied tableId doesn't match the row's tableId" @@ -241,12 +241,12 @@ exports.destroy = async function (ctx) { }) if (ctx.params.tableId === InternalTables.USER_METADATA) { ctx.params = { - id: ctx.params.rowId, + id: rowId, } await userController.destroyMetadata(ctx) return { response: ctx.body, row } } else { - const response = await db.remove(ctx.params.rowId, ctx.params.revId) + const response = await db.remove(rowId, revId) return { response, row } } } diff --git a/packages/server/src/api/routes/row.js b/packages/server/src/api/routes/row.js index ca1e170754..b155552776 100644 --- a/packages/server/src/api/routes/row.js +++ b/packages/server/src/api/routes/row.js @@ -52,8 +52,8 @@ router rowController.validate ) .delete( - "/api/:tableId/rows/:rowId/:revId", - paramSubResource("tableId", "rowId"), + "/api/:tableId/rows", + paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), usage, rowController.destroy diff --git a/packages/server/src/automations/steps/deleteRow.js b/packages/server/src/automations/steps/deleteRow.js index b6af7ecaab..9dde91fa30 100644 --- a/packages/server/src/automations/steps/deleteRow.js +++ b/packages/server/src/automations/steps/deleteRow.js @@ -62,8 +62,12 @@ module.exports.run = async function ({ inputs, appId, apiKey, emitter }) { let ctx = { params: { tableId: inputs.tableId, - rowId: inputs.id, - revId: inputs.revision, + }, + request: { + body: { + rowId: inputs.id, + revId: inputs.revision, + }, }, appId, eventEmitter: emitter,