2022-02-24 07:31:32 +13:00
|
|
|
const { search } = require("./utils")
|
|
|
|
const { getAllApps } = require("@budibase/backend-core/db")
|
|
|
|
const { updateAppId } = require("@budibase/backend-core/context")
|
|
|
|
const controller = require("../application")
|
2022-02-22 08:04:13 +13:00
|
|
|
|
2022-02-24 07:31:32 +13:00
|
|
|
async function setResponseApp(ctx) {
|
|
|
|
if (ctx.body && ctx.body.appId && (!ctx.params || !ctx.params.appId)) {
|
|
|
|
ctx.params = { appId: ctx.body.appId }
|
|
|
|
}
|
|
|
|
await controller.fetchAppPackage(ctx)
|
|
|
|
}
|
2022-02-22 08:04:13 +13:00
|
|
|
|
2022-02-24 07:31:32 +13:00
|
|
|
exports.search = async ctx => {
|
|
|
|
const { name } = ctx.request.body
|
|
|
|
const apps = await getAllApps({ all: true })
|
|
|
|
ctx.body = {
|
2022-02-24 11:13:16 +13:00
|
|
|
applications: search(apps, name),
|
2022-02-24 07:31:32 +13:00
|
|
|
}
|
|
|
|
}
|
2022-02-22 08:04:13 +13:00
|
|
|
|
2022-02-24 07:31:32 +13:00
|
|
|
exports.create = async ctx => {
|
|
|
|
await controller.create(ctx)
|
|
|
|
await setResponseApp(ctx)
|
|
|
|
}
|
2022-02-22 08:04:13 +13:00
|
|
|
|
2022-02-24 07:31:32 +13:00
|
|
|
exports.read = async ctx => {
|
|
|
|
updateAppId(ctx.params.appId)
|
|
|
|
await setResponseApp(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.update = async ctx => {
|
|
|
|
updateAppId(ctx.params.appId)
|
|
|
|
await controller.update(ctx)
|
|
|
|
await setResponseApp(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.delete = async ctx => {
|
|
|
|
updateAppId(ctx.params.appId)
|
|
|
|
// get the app before deleting it
|
|
|
|
await setResponseApp(ctx)
|
|
|
|
const body = ctx.body
|
|
|
|
await controller.delete(ctx)
|
|
|
|
// overwrite the body again
|
|
|
|
ctx.body = body
|
|
|
|
}
|