Clear quota cache on deprovision + gracefully handle account metadata doc deletion
This commit is contained in:
parent
5b576d23a5
commit
1fc704511d
|
@ -1,6 +1,7 @@
|
||||||
const { StaticDatabases, doWithDB } = require("@budibase/backend-core/db")
|
const { StaticDatabases, doWithDB } = require("@budibase/backend-core/db")
|
||||||
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
||||||
const { deleteTenant } = require("@budibase/backend-core/deprovision")
|
const { deleteTenant } = require("@budibase/backend-core/deprovision")
|
||||||
|
const { quotas } = require("@budibase/pro")
|
||||||
|
|
||||||
exports.exists = async ctx => {
|
exports.exists = async ctx => {
|
||||||
const tenantId = ctx.request.params
|
const tenantId = ctx.request.params
|
||||||
|
@ -48,6 +49,7 @@ exports.delete = async ctx => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteTenant(tenantId)
|
await deleteTenant(tenantId)
|
||||||
|
await quotas.bustCache()
|
||||||
ctx.status = 204
|
ctx.status = 204
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.log.error(err)
|
ctx.log.error(err)
|
||||||
|
|
|
@ -47,10 +47,7 @@ describe("accounts", () => {
|
||||||
|
|
||||||
const response = await api.accounts.destroyMetadata(id)
|
const response = await api.accounts.destroyMetadata(id)
|
||||||
|
|
||||||
expect(response.status).toBe(404)
|
expect(response.status).toBe(204)
|
||||||
expect(response.body.message).toBe(
|
|
||||||
`id=${accounts.formatAccountMetadataId(id)} does not exist`
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,8 +46,14 @@ export const destroyMetadata = async (accountId: string) => {
|
||||||
await db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
await db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => {
|
||||||
const metadata = await getMetadata(accountId)
|
const metadata = await getMetadata(accountId)
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
throw new HTTPError(`id=${accountId} does not exist`, 404)
|
return
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
await db.remove(accountId, metadata._rev)
|
await db.remove(accountId, metadata._rev)
|
||||||
|
} catch (e: any) {
|
||||||
|
if (e.status !== 404) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue