Refactored approach to ensure the request context is set appropriately
This commit is contained in:
parent
550f6f4d61
commit
e9554562bb
|
@ -298,9 +298,6 @@ function getContextDB(key, opts) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the appId is specified, override context
|
|
||||||
toUseAppId = opts?.appId ? opts?.appId : toUseAppId
|
|
||||||
|
|
||||||
db = dangerousGetDB(toUseAppId, opts)
|
db = dangerousGetDB(toUseAppId, opts)
|
||||||
try {
|
try {
|
||||||
cls.setOnContext(key, db)
|
cls.setOnContext(key, db)
|
||||||
|
|
|
@ -49,6 +49,7 @@ const {
|
||||||
getAppDB,
|
getAppDB,
|
||||||
getProdAppDB,
|
getProdAppDB,
|
||||||
updateAppId,
|
updateAppId,
|
||||||
|
doInAppContext,
|
||||||
} = require("@budibase/backend-core/context")
|
} = require("@budibase/backend-core/context")
|
||||||
import { getUniqueRows } from "../../utilities/usageQuota/rows"
|
import { getUniqueRows } from "../../utilities/usageQuota/rows"
|
||||||
import { quotas } from "@budibase/pro"
|
import { quotas } from "@budibase/pro"
|
||||||
|
@ -340,6 +341,7 @@ export const update = async (ctx: any) => {
|
||||||
const data = await updateAppPackage(ctx.request.body, ctx.params.appId)
|
const data = await updateAppPackage(ctx.request.body, ctx.params.appId)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = data
|
ctx.body = data
|
||||||
|
console.log(JSON.stringify(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateClient = async (ctx: any) => {
|
export const updateClient = async (ctx: any) => {
|
||||||
|
@ -502,7 +504,8 @@ export const sync = async (ctx: any, next: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateAppPackage = async (appPackage: any, appId: any) => {
|
const updateAppPackage = async (appPackage: any, appId: any) => {
|
||||||
const db = getAppDB({ appId })
|
return doInAppContext(appId, async () => {
|
||||||
|
const db = getAppDB()
|
||||||
const application = await db.get(DocumentTypes.APP_METADATA)
|
const application = await db.get(DocumentTypes.APP_METADATA)
|
||||||
|
|
||||||
const newAppPackage = { ...application, ...appPackage }
|
const newAppPackage = { ...application, ...appPackage }
|
||||||
|
@ -518,6 +521,7 @@ const updateAppPackage = async (appPackage: any, appId: any) => {
|
||||||
// remove any cached metadata, so that it will be updated
|
// remove any cached metadata, so that it will be updated
|
||||||
await appCache.invalidateAppMetadata(appId)
|
await appCache.invalidateAppMetadata(appId)
|
||||||
return response
|
return response
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const createEmptyAppPackage = async (ctx: any, app: any) => {
|
const createEmptyAppPackage = async (ctx: any, app: any) => {
|
||||||
|
|
Loading…
Reference in New Issue