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

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-05-07 21:53:34 +12:00
const CouchDB = require("../../db")
const ClientDb = require("../../db/clientDb")
2020-05-07 21:53:34 +12:00
const { getPackageForBuilder } = require("../../utilities/builder")
2020-05-19 03:22:09 +12:00
const newid = require("../../db/newid")
2020-05-15 02:12:30 +12:00
const env = require("../../environment")
2020-04-08 04:25:09 +12:00
2020-04-10 03:53:48 +12:00
exports.fetch = async function(ctx) {
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
const body = await db.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) {
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
const application = await db.get(ctx.params.applicationId)
2020-05-07 21:53:34 +12:00
ctx.body = await getPackageForBuilder(ctx.config, application)
}
2020-04-10 03:53:48 +12:00
exports.create = async function(ctx) {
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
2020-05-15 02:12:30 +12:00
const newApplication = {
2020-05-19 03:22:09 +12:00
_id: newid(),
type: "app",
instances: [],
userInstanceMap: {},
componentLibraries: [
"@budibase/standard-components",
2020-05-07 21:53:34 +12:00
"@budibase/materialdesign-components",
],
...ctx.request.body,
2020-04-10 03:53:48 +12:00
}
2020-05-15 02:12:30 +12:00
const { rev } = await db.post(newApplication)
2020-05-15 02:12:30 +12:00
newApplication._rev = rev
2020-05-18 21:28:38 +12:00
2020-05-15 02:12:30 +12:00
ctx.body = newApplication
ctx.message = `Application ${ctx.request.body.name} created successfully`
2020-05-07 21:53:34 +12:00
}