2020-05-07 11:53:34 +02:00
|
|
|
const CouchDB = require("../../db")
|
2020-05-18 07:40:29 +02:00
|
|
|
const ClientDb = require("../../db/clientDb")
|
2020-05-07 11:53:34 +02:00
|
|
|
const { getPackageForBuilder } = require("../../utilities/builder")
|
2020-05-14 16:12:30 +02:00
|
|
|
const uuid = require("uuid")
|
|
|
|
const env = require("../../environment")
|
2020-04-07 18:25:09 +02:00
|
|
|
|
2020-04-09 17:53:48 +02:00
|
|
|
exports.fetch = async function(ctx) {
|
2020-05-18 07:40:29 +02:00
|
|
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
|
|
|
const body = await db.query("client/by_type", {
|
2020-04-09 17:53:48 +02:00
|
|
|
include_docs: true,
|
2020-05-07 11:53:34 +02:00
|
|
|
key: ["app"],
|
|
|
|
})
|
2020-04-08 17:57:27 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
ctx.body = body.rows.map(row => row.doc)
|
|
|
|
}
|
2020-04-07 18:25:09 +02:00
|
|
|
|
2020-04-20 17:17:11 +02:00
|
|
|
exports.fetchAppPackage = async function(ctx) {
|
2020-05-18 07:40:29 +02:00
|
|
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
|
|
|
const application = await db.get(ctx.params.applicationId)
|
2020-05-07 11:53:34 +02:00
|
|
|
ctx.body = await getPackageForBuilder(ctx.config, application)
|
2020-04-20 17:17:11 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 17:53:48 +02:00
|
|
|
exports.create = async function(ctx) {
|
2020-05-18 07:40:29 +02:00
|
|
|
const db = new CouchDB(ClientDb.name(env.CLIENT_ID))
|
2020-05-14 16:12:30 +02:00
|
|
|
|
|
|
|
const newApplication = {
|
|
|
|
_id: uuid.v4().replace(/-/g, ""),
|
2020-04-20 17:17:11 +02:00
|
|
|
type: "app",
|
|
|
|
instances: [],
|
2020-05-04 19:07:03 +02:00
|
|
|
userInstanceMap: {},
|
2020-05-02 16:29:10 +02:00
|
|
|
componentLibraries: [
|
|
|
|
"@budibase/standard-components",
|
2020-05-07 11:53:34 +02:00
|
|
|
"@budibase/materialdesign-components",
|
2020-05-02 16:29:10 +02:00
|
|
|
],
|
2020-04-20 17:17:11 +02:00
|
|
|
...ctx.request.body,
|
2020-04-09 17:53:48 +02:00
|
|
|
}
|
2020-05-14 16:12:30 +02:00
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
const { rev } = await db.post(newApplication)
|
2020-05-14 16:12:30 +02:00
|
|
|
newApplication._rev = rev
|
|
|
|
ctx.body = newApplication
|
|
|
|
ctx.message = `Application ${ctx.request.body.name} created successfully`
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|