UNPKG

@tachybase/plugin-workflow-approval

Version:

Approval base in Workflow

104 lines (103 loc) 4.39 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 ApprovalCarbonCopy_exports = {}; __export(ApprovalCarbonCopy_exports, { default: () => ApprovalCarbonCopyInstruction }); module.exports = __toCommonJS(ApprovalCarbonCopy_exports); var import_module_workflow = require("@tachybase/module-workflow"); var import_server = require("@tego/server"); var import_constants = require("../../common/constants"); var import_status = require("../constants/status"); var import_tools = require("../tools"); class ApprovalCarbonCopyInstruction extends import_module_workflow.Instruction { async run(node, prevJob, processor) { const job = await processor.saveJob({ status: import_module_workflow.JOB_STATUS.RESOLVED, nodeId: node.id, nodeKey: node.key, upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null }); const targetPersonList = await (0, import_tools.parsePerson)({ node, processor, keyName: "carbonCopyPerson" }); if (targetPersonList && targetPersonList.length > 0) { const { db } = processor.options.plugin; const ApprovalRepo = db.getRepository("approvals"); const approval = await ApprovalRepo.findOne({ filter: { "executions.id": processor.execution.id }, fields: ["id", "status", "data", "summary", "collectionName"], appends: ["approvalExecutions", "createdBy"], except: ["data"] }); if ([import_status.APPROVAL_STATUS.SUBMITTED, import_status.APPROVAL_STATUS.ERROR].includes(approval.status)) { const CarbonCopyModel = db.getModel(import_constants.COLLECTION_NAME_APPROVAL_CARBON_COPY); const notifiedPersonDataMap = targetPersonList.map((userId, index) => { var _a; return { userId, jobId: job.id, nodeId: node.id, executionId: job.executionId, workflowId: node.workflowId, index, createdById: (_a = approval.createdBy) == null ? void 0 : _a.id, approvalId: approval.id, status: approval.status, snapshot: approval.data, summary: approval.summary, collectionName: approval.collectionName, dataKey: approval.dataKey }; }); await CarbonCopyModel.bulkCreate(notifiedPersonDataMap, { transaction: processor.transaction }); for (const userId of targetPersonList) { const [dataSourceName] = (0, import_server.parseCollectionName)(approval.collectionName); const collection = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(approval.collectionName); const message = { userId, title: '{{t("Approval Carbon Copy", { ns: "workflow-approval" })}}', content: "", jsonContent: approval.summary, collectionName: approval.collectionName, schemaName: node.config.showCarbonCopyDetail, dataKey: approval.data[collection.filterTargetKey] }; this.workflow.app.messageManager.sendMessage(+userId, message); } } } return job; } async duplicateConfig(node, { transaction }) { const keyName = "showCarbonCopyDetail"; const uiSchemaRepo = this.workflow.app.db.getRepository("uiSchemas"); if (!node.config[keyName]) { return node.config; } const resultSchema = await uiSchemaRepo.duplicate(node.config[keyName], { transaction }); return { ...node.config, [keyName]: resultSchema == null ? void 0 : resultSchema["x-uid"] }; } }