Fixing bulk deletion.

This commit is contained in:
mike12345567 2021-06-11 19:54:47 +01:00
parent 6b40f15318
commit 6685ebaa7b
5 changed files with 15 additions and 12 deletions

View File

@ -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`)

View File

@ -9,7 +9,7 @@
async function confirmDeletion() {
await deleteRows()
modal.hide()
modal?.hide()
}
</script>

View File

@ -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 }
}
}

View File

@ -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

View File

@ -62,9 +62,13 @@ module.exports.run = async function ({ inputs, appId, apiKey, emitter }) {
let ctx = {
params: {
tableId: inputs.tableId,
},
request: {
body: {
rowId: inputs.id,
revId: inputs.revision,
},
},
appId,
eventEmitter: emitter,
}