1
0
Fork 0
mirror of synced 2024-06-17 18:04:42 +12:00

Fix for #5709 making sure public API can update existing apps.

This commit is contained in:
mike12345567 2022-07-05 18:52:53 +01:00
parent 1742c071cc
commit 18df43e197
2 changed files with 10 additions and 3 deletions

View file

@ -1,6 +1,6 @@
const { getAllApps } = require("@budibase/backend-core/db")
const { updateAppId } = require("@budibase/backend-core/context")
import { search as stringSearch } from "./utils"
import { search as stringSearch, addRev } from "./utils"
import * as controller from "../application"
import { Application } from "../../../definitions/common"
@ -47,7 +47,7 @@ export async function read(ctx: any, next: any) {
}
export async function update(ctx: any, next: any) {
ctx.request.body = fixAppID(ctx.request.body, ctx.params)
ctx.request.body = await addRev(fixAppID(ctx.request.body, ctx.params))
updateAppId(ctx.params.appId)
await controller.update(ctx)
await setResponseApp(ctx)

View file

@ -1,5 +1,6 @@
const { getAppDB } = require("@budibase/backend-core/context")
import { isExternalTable } from "../../../integrations/utils"
import { APP_PREFIX, DocumentTypes } from "../../../db/utils"
export async function addRev(
body: { _id?: string; _rev?: string },
@ -8,9 +9,15 @@ export async function addRev(
if (!body._id || (tableId && isExternalTable(tableId))) {
return body
}
let id = body._id
if (body._id.startsWith(APP_PREFIX)) {
id = DocumentTypes.APP_METADATA
}
const db = getAppDB()
const dbDoc = await db.get(body._id)
const dbDoc = await db.get(id)
body._rev = dbDoc._rev
// update ID in case it is an app ID
body._id = id
return body
}