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