Fix for #5709 making sure public API can update existing apps.
This commit is contained in:
parent
1742c071cc
commit
18df43e197
|
@ -1,6 +1,6 @@
|
||||||
const { getAllApps } = require("@budibase/backend-core/db")
|
const { getAllApps } = require("@budibase/backend-core/db")
|
||||||
const { updateAppId } = require("@budibase/backend-core/context")
|
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 * as controller from "../application"
|
||||||
import { Application } from "../../../definitions/common"
|
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) {
|
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)
|
updateAppId(ctx.params.appId)
|
||||||
await controller.update(ctx)
|
await controller.update(ctx)
|
||||||
await setResponseApp(ctx)
|
await setResponseApp(ctx)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
const { getAppDB } = require("@budibase/backend-core/context")
|
||||||
import { isExternalTable } from "../../../integrations/utils"
|
import { isExternalTable } from "../../../integrations/utils"
|
||||||
|
import { APP_PREFIX, DocumentTypes } from "../../../db/utils"
|
||||||
|
|
||||||
export async function addRev(
|
export async function addRev(
|
||||||
body: { _id?: string; _rev?: string },
|
body: { _id?: string; _rev?: string },
|
||||||
|
@ -8,9 +9,15 @@ export async function addRev(
|
||||||
if (!body._id || (tableId && isExternalTable(tableId))) {
|
if (!body._id || (tableId && isExternalTable(tableId))) {
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
let id = body._id
|
||||||
|
if (body._id.startsWith(APP_PREFIX)) {
|
||||||
|
id = DocumentTypes.APP_METADATA
|
||||||
|
}
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
const dbDoc = await db.get(body._id)
|
const dbDoc = await db.get(id)
|
||||||
body._rev = dbDoc._rev
|
body._rev = dbDoc._rev
|
||||||
|
// update ID in case it is an app ID
|
||||||
|
body._id = id
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue