1
0
Fork 0
mirror of synced 2024-06-17 09:55:09 +12:00
budibase/packages/server/src/api/controllers/public/applications.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

const { search } = require("./utils")
const { getAllApps } = require("@budibase/backend-core/db")
const { updateAppId } = require("@budibase/backend-core/context")
const controller = require("../application")
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)
}
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),
}
}
exports.create = async ctx => {
await controller.create(ctx)
await setResponseApp(ctx)
}
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
}