UNPKG

@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.13 kB
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(context, next) { context.action.mergeParams({ filter: { type: import_constants.NOTICE_INSTRUCTION_NAMESPACE, enabled: true } }); return import_server.actions.list(context, next); } }; const workflowNotice = { async listCentralized(context, next) { const centralizedNoticeFlow = await context.db.getRepository(import_workflowNotice.COLLECTION_WORKFLOWS_NAME).find({ filter: { "config.centralized": true }, fields: ["id"] }); context.action.mergeParams({ filter: { workflowId: centralizedNoticeFlow.map((item) => item.id) } }); return import_server.actions.list(context, next); }, async submit(context, next) { const repository = import_server.utils.getRepositoryFromParams(context); const { filterByTk, values } = context.action.params; const { currentUser } = context.state; if (!currentUser) { return context.throw(401); } const workflowNotice2 = await repository.findOne({ filterByTk, filter: { userId: currentUser == null ? void 0 : currentUser.id }, appends: ["job", "node", "execution", "workflow"], context }); if (!workflowNotice2) { return context.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 context.throw(400); } await workflowNotice2.update({ status: values.status // comment: values.comment, // snapshot: workflowNotice.approval.data, // summary: workflowNotice.approval.summary, // collectionName: workflowNotice.approval.collectionName, }); context.body = workflowNotice2.get(); context.status = 202; await next(); workflowNotice2.execution.workflow = workflowNotice2.workflow; workflowNotice2.job.execution = workflowNotice2.execution; workflowNotice2.job.latestUserJob = workflowNotice2.get(); const workflow = context.app.getPlugin(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.actions({ ...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 });