From e8053b55e6df829925698e3bc4552d7e06a34bd8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 21 Jul 2022 16:39:55 +0100 Subject: [PATCH] Fixing issue with app DB not being in context for fetch. --- .../api/controllers/public/applications.ts | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/server/src/api/controllers/public/applications.ts b/packages/server/src/api/controllers/public/applications.ts index 6fa5185d23..c2c62ffc28 100644 --- a/packages/server/src/api/controllers/public/applications.ts +++ b/packages/server/src/api/controllers/public/applications.ts @@ -1,5 +1,5 @@ const { getAllApps } = require("@budibase/backend-core/db") -const { updateAppId } = require("@budibase/backend-core/context") +const { doInAppContext } = require("@budibase/backend-core/context") import { search as stringSearch, addRev } from "./utils" import * as controller from "../application" import { Application } from "../../../definitions/common" @@ -41,28 +41,31 @@ export async function create(ctx: any, next: any) { } export async function read(ctx: any, next: any) { - updateAppId(ctx.params.appId) - await setResponseApp(ctx) - await next() + await doInAppContext(ctx.params.appId, async () => { + await setResponseApp(ctx) + await next() + }) } export async function update(ctx: any, next: any) { ctx.request.body = await addRev(fixAppID(ctx.request.body, ctx.params)) - updateAppId(ctx.params.appId) - await controller.update(ctx) - await setResponseApp(ctx) - await next() + await doInAppContext(ctx.params.appId, async () => { + await controller.update(ctx) + await setResponseApp(ctx) + await next() + }) } export async function destroy(ctx: any, next: any) { - updateAppId(ctx.params.appId) - // get the app before deleting it - await setResponseApp(ctx) - const body = ctx.body - await controller.destroy(ctx) - // overwrite the body again - ctx.body = body - await next() + await doInAppContext(ctx.params.appId, async () => { + // get the app before deleting it + await setResponseApp(ctx) + const body = ctx.body + await controller.destroy(ctx) + // overwrite the body again + ctx.body = body + await next() + }) } export default {