@tachybase/module-workflow
Version:
A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.
115 lines (114 loc) • 4.08 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var actions_exports = {};
__export(actions_exports, {
init: () => init
});
module.exports = __toCommonJS(actions_exports);
var import_server = require("@tego/server");
var import__ = require("../..");
var import_constants = require("../common/constants");
var import_workflowNotice = require("./collections/workflowNotice");
var import_constants2 = require("./constants");
const workflows = {
async listWorkflowNoticeFlows(ctx, next) {
ctx.action.mergeParams({
filter: {
type: import_constants.NOTICE_INSTRUCTION_NAMESPACE,
enabled: true
}
});
return import_server.actions.list(ctx, next);
}
};
const workflowNotice = {
async listCentralized(ctx, next) {
const centralizedNoticeFlow = await ctx.db.getRepository(import_workflowNotice.COLLECTION_WORKFLOWS_NAME).find({
filter: {
"config.centralized": true
},
fields: ["id"]
});
ctx.action.mergeParams({
filter: {
workflowId: centralizedNoticeFlow.map((item) => item.id)
}
});
return import_server.actions.list(ctx, next);
},
async submit(ctx, next) {
const repository = import_server.utils.getRepositoryFromParams(ctx);
const { filterByTk, values } = ctx.action.params;
const { currentUser } = ctx.state;
if (!currentUser) {
return ctx.throw(401);
}
const workflowNotice2 = await repository.findOne({
filterByTk,
filter: {
userId: currentUser == null ? void 0 : currentUser.id
},
appends: ["job", "node", "execution", "workflow"],
context: ctx
});
if (!workflowNotice2) {
return ctx.throw(404);
}
if (!workflowNotice2.workflow.enabled || workflowNotice2.execution.status || workflowNotice2.job.status || workflowNotice2.status !== import_constants2.NOTICE_ACTION_STATUS.PENDING || !(workflowNotice2.node.config.actions ?? []).includes(values.status)) {
return ctx.throw(400);
}
await workflowNotice2.update({
status: values.status
// comment: values.comment,
// snapshot: workflowNotice.approval.data,
// summary: workflowNotice.approval.summary,
// collectionName: workflowNotice.approval.collectionName,
});
ctx.body = workflowNotice2.get();
ctx.status = 202;
await next();
workflowNotice2.execution.workflow = workflowNotice2.workflow;
workflowNotice2.job.execution = workflowNotice2.execution;
workflowNotice2.job.latestUserJob = workflowNotice2.get();
const workflow = ctx.tego.pm.get(import__.PluginWorkflow);
const processor = workflow.createProcessor(workflowNotice2.execution);
processor.logger.info(
`notice node (${workflowNotice2.nodeId}) action trigger execution (${workflowNotice2.execution.id}) to resume`
);
workflow.resume(workflowNotice2.job);
}
};
function init({ app }) {
app.resourcer.registerActions({
...make(import_workflowNotice.COLLECTION_WORKFLOWS_NAME, workflows),
...make(import_constants.COLLECTION_NOTICE_NAME, workflowNotice)
});
}
function make(name, mod) {
return Object.keys(mod).reduce(
(result, key) => ({
...result,
[`${name}:${key}`]: mod[key]
}),
{}
);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
init
});