1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +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 () => { const deleteRows = async () => {
await api.post(`/api/${tableId}/rows`, { await api.delete(`/api/${tableId}/rows`, {
rows: selectedRows, rows: selectedRows,
type: "delete",
}) })
data = data.filter(row => !selectedRows.includes(row)) data = data.filter(row => !selectedRows.includes(row))
notifications.success(`Successfully deleted ${selectedRows.length} rows`) notifications.success(`Successfully deleted ${selectedRows.length} rows`)

View file

@ -9,7 +9,7 @@
async function confirmDeletion() { async function confirmDeletion() {
await deleteRows() await deleteRows()
modal.hide() modal?.hide()
} }
</script> </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 this is a table view being looked for just transfer to that
if (viewName.startsWith(TABLE_VIEW_BEGINS_WITH)) { if (viewName.startsWith(TABLE_VIEW_BEGINS_WITH)) {
ctx.params.tableId = viewName.substring(4) ctx.params.tableId = viewName.substring(4)
await exports.fetchTableRows(ctx) return exports.fetchTableRows(ctx)
return
} }
const db = new CouchDB(appId) const db = new CouchDB(appId)
@ -228,7 +227,8 @@ exports.find = async (ctx) => {
exports.destroy = async function (ctx) { exports.destroy = async function (ctx) {
const appId = ctx.appId const appId = ctx.appId
const db = new CouchDB(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) { if (row.tableId !== ctx.params.tableId) {
throw "Supplied tableId doesn't match the row's 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) { if (ctx.params.tableId === InternalTables.USER_METADATA) {
ctx.params = { ctx.params = {
id: ctx.params.rowId, id: rowId,
} }
await userController.destroyMetadata(ctx) await userController.destroyMetadata(ctx)
return { response: ctx.body, row } return { response: ctx.body, row }
} else { } else {
const response = await db.remove(ctx.params.rowId, ctx.params.revId) const response = await db.remove(rowId, revId)
return { response, row } return { response, row }
} }
} }

View file

@ -52,8 +52,8 @@ router
rowController.validate rowController.validate
) )
.delete( .delete(
"/api/:tableId/rows/:rowId/:revId", "/api/:tableId/rows",
paramSubResource("tableId", "rowId"), paramResource("tableId"),
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
usage, usage,
rowController.destroy rowController.destroy

View file

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