2020-05-20 18:02:46 +02:00
|
|
|
const CouchDB = require("../../db")
|
|
|
|
const newid = require("../../db/newid")
|
|
|
|
|
|
|
|
exports.create = async function(ctx) {
|
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
|
|
|
const workflow = ctx.request.body
|
|
|
|
|
|
|
|
workflow._id = newid()
|
|
|
|
|
|
|
|
workflow.type = "workflow"
|
|
|
|
const response = await db.post(workflow)
|
|
|
|
workflow._rev = response.rev
|
|
|
|
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = {
|
|
|
|
message: "Workflow created successfully",
|
|
|
|
workflow: {
|
|
|
|
...workflow,
|
2020-05-27 13:51:19 +02:00
|
|
|
...response,
|
2020-05-28 21:20:03 +02:00
|
|
|
},
|
|
|
|
}
|
2020-05-20 18:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.update = async function(ctx) {
|
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
2020-05-28 21:20:03 +02:00
|
|
|
const workflow = ctx.request.body
|
2020-05-22 17:32:23 +02:00
|
|
|
|
|
|
|
const response = await db.put(workflow)
|
|
|
|
workflow._rev = response.rev
|
|
|
|
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = {
|
|
|
|
message: `Workflow ${workflow._id} updated successfully.`,
|
|
|
|
workflow: {
|
|
|
|
...workflow,
|
|
|
|
_rev: response.rev,
|
2020-05-28 21:20:03 +02:00
|
|
|
_id: response.id,
|
2020-05-22 17:32:23 +02:00
|
|
|
},
|
|
|
|
}
|
2020-05-20 18:02:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetch = async function(ctx) {
|
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
|
|
|
const response = await db.query(`database/by_type`, {
|
2020-05-27 22:51:32 +02:00
|
|
|
key: ["workflow"],
|
2020-05-20 18:02:46 +02:00
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
ctx.body = response.rows.map(row => row.doc)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.find = async function(ctx) {
|
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
|
|
|
ctx.body = await db.get(ctx.params.id)
|
|
|
|
}
|
|
|
|
|
2020-05-26 22:34:01 +02:00
|
|
|
exports.executeAction = async function(ctx) {
|
2020-05-28 21:20:03 +02:00
|
|
|
const workflowAction = require(`./actions/${ctx.request.body.action}`)
|
|
|
|
const response = await workflowAction(ctx.request.body.args)
|
|
|
|
ctx.body = response
|
2020-05-26 22:34:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.fetchActionScript = async function(ctx) {
|
2020-05-28 21:20:03 +02:00
|
|
|
const workflowAction = require(`./actions/${ctx.action}`)
|
|
|
|
console.log(workflowAction)
|
|
|
|
ctx.body = workflowAction
|
2020-05-26 22:34:01 +02:00
|
|
|
}
|
|
|
|
|
2020-05-20 18:02:46 +02:00
|
|
|
exports.destroy = async function(ctx) {
|
|
|
|
const db = new CouchDB(ctx.params.instanceId)
|
|
|
|
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
|
|
|
}
|