1
0
Fork 0
mirror of synced 2024-06-23 08:30:31 +12:00

Fixing bulk deletion.

This commit is contained in:
mike12345567 2021-06-11 19:54:47 +01:00
parent 190e17cc4c
commit 9719e26de2
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,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,