1
0
Fork 0
mirror of synced 2024-06-16 01:14:48 +12:00
budibase/packages/server/src/api/controllers/application.js

39 lines
1 KiB
JavaScript
Raw Normal View History

2020-05-07 21:53:34 +12:00
const CouchDB = require("../../db")
const { getPackageForBuilder } = require("../../utilities/builder")
2020-04-08 04:25:09 +12:00
2020-04-10 03:53:48 +12:00
exports.fetch = async function(ctx) {
2020-05-07 21:53:34 +12:00
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
const body = await clientDb.query("client/by_type", {
2020-04-10 03:53:48 +12:00
include_docs: true,
2020-05-07 21:53:34 +12:00
key: ["app"],
})
2020-04-09 03:57:27 +12:00
2020-05-07 21:53:34 +12:00
ctx.body = body.rows.map(row => row.doc)
}
2020-04-08 04:25:09 +12:00
exports.fetchAppPackage = async function(ctx) {
2020-05-07 21:53:34 +12:00
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
const application = await clientDb.get(ctx.params.applicationId)
ctx.body = await getPackageForBuilder(ctx.config, application)
}
2020-04-10 03:53:48 +12:00
exports.create = async function(ctx) {
2020-05-07 21:53:34 +12:00
const clientDb = new CouchDB(`client-${ctx.params.clientId}`)
const { id, rev } = await clientDb.post({
type: "app",
instances: [],
userInstanceMap: {},
componentLibraries: [
"@budibase/standard-components",
2020-05-07 21:53:34 +12:00
"@budibase/materialdesign-components",
],
...ctx.request.body,
2020-05-07 21:53:34 +12:00
})
2020-04-10 03:53:48 +12:00
ctx.body = {
id,
rev,
2020-05-07 21:53:34 +12:00
message: `Application ${ctx.request.body.name} created successfully`,
2020-04-10 03:53:48 +12:00
}
2020-05-07 21:53:34 +12:00
}