Implement deletes
This commit is contained in:
parent
4bbb1b0289
commit
4ca25ee065
|
@ -1,4 +1,3 @@
|
|||
import { DocumentType, SEPARATOR } from "@budibase/backend-core"
|
||||
import sdk from "../../../sdk"
|
||||
import { Ctx, ViewV2 } from "@budibase/types"
|
||||
|
||||
|
@ -29,3 +28,11 @@ export async function save(ctx: Ctx<ViewV2>) {
|
|||
...result,
|
||||
}
|
||||
}
|
||||
|
||||
export async function remove(ctx: Ctx) {
|
||||
const { viewId } = ctx.params
|
||||
const { _rev } = await sdk.views.get(viewId)
|
||||
|
||||
await sdk.views.remove(viewId, _rev)
|
||||
ctx.status = 204
|
||||
}
|
||||
|
|
|
@ -158,4 +158,30 @@ describe("/views/v2", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete", () => {
|
||||
let view: any
|
||||
|
||||
beforeAll(async () => {
|
||||
table = await config.createTable(priceTable())
|
||||
view = (await saveView(createView(table._id!))).body
|
||||
})
|
||||
|
||||
it("can delete an existing view", async () => {
|
||||
await getView({
|
||||
tableId: view.tableId,
|
||||
viewId: view._id,
|
||||
}).expect(200)
|
||||
|
||||
await request
|
||||
.delete(`/api/views/v2/${view.tableId}/${view._id}`)
|
||||
.set(config.defaultHeaders())
|
||||
.expect(204)
|
||||
|
||||
await getView({
|
||||
tableId: view.tableId,
|
||||
viewId: view._id,
|
||||
}).expect(404)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -28,6 +28,11 @@ router
|
|||
authorized(permissions.BUILDER),
|
||||
viewController.v2.save
|
||||
)
|
||||
.delete(
|
||||
`/api/views/v2/:tableId/:viewId`,
|
||||
authorized(permissions.BUILDER),
|
||||
viewController.v2.remove
|
||||
)
|
||||
|
||||
router
|
||||
.get(
|
||||
|
|
|
@ -54,3 +54,8 @@ export async function save(view: ViewV2) {
|
|||
_rev: response.rev,
|
||||
}
|
||||
}
|
||||
|
||||
export async function remove(viewId: string, rev: string) {
|
||||
const db = context.getAppDB()
|
||||
await db.remove(viewId, rev)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue