@steedos/process 2.2.52 → 2.2.53-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/approve.js +70 -24
- package/lib/approve.js.map +1 -1
- package/lib/express-middleware.js +9 -9
- package/lib/express-middleware.js.map +1 -1
- package/lib/index.js +13 -2
- package/lib/index.js.map +1 -1
- package/lib/notifications.js +93 -42
- package/lib/notifications.js.map +1 -1
- package/lib/permission.js +111 -50
- package/lib/permission.js.map +1 -1
- package/lib/permission_manager.js +102 -40
- package/lib/permission_manager.js.map +1 -1
- package/lib/platform_action_manager.js +185 -91
- package/lib/platform_action_manager.js.map +1 -1
- package/lib/process_manager.js +770 -398
- package/lib/process_manager.js.map +1 -1
- package/lib/reassign.js +69 -23
- package/lib/reassign.js.map +1 -1
- package/lib/recall.js +73 -30
- package/lib/recall.js.map +1 -1
- package/lib/reject.js +68 -22
- package/lib/reject.js.map +1 -1
- package/lib/submit.js +68 -22
- package/lib/submit.js.map +1 -1
- package/package.json +5 -4
package/lib/process_manager.js
CHANGED
|
@@ -1,91 +1,180 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const lockObjectRecord = async (objectName, reocrdId) => {
|
|
11
|
-
await objectql.getObject(objectName).directUpdate(reocrdId, { locked: true });
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
12
10
|
};
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
15
37
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.processInstanceWorkitemRemovebyInstance = exports.processInstanceWorkitemReassign = exports.processInstanceWorkitemReject = exports.processInstanceWorkitemApprove = exports.getProcessInstanceWorkitem = exports.getReocrdProcessInstance = exports.recordSubmit = exports.getObjectProcessDefinition = void 0;
|
|
40
|
+
var platform_action_manager_1 = require("./platform_action_manager");
|
|
41
|
+
var notifications_1 = require("./notifications");
|
|
42
|
+
var objectql_1 = require("@steedos/objectql");
|
|
43
|
+
var objectql = require('@steedos/objectql');
|
|
44
|
+
var Fiber = require('fibers');
|
|
45
|
+
var _ = require("underscore");
|
|
46
|
+
var lockObjectRecord = function (objectName, reocrdId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
switch (_a.label) {
|
|
49
|
+
case 0: return [4 /*yield*/, objectql.getObject(objectName).directUpdate(reocrdId, { locked: true })];
|
|
50
|
+
case 1:
|
|
51
|
+
_a.sent();
|
|
52
|
+
return [2 /*return*/];
|
|
26
53
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
});
|
|
55
|
+
}); };
|
|
56
|
+
var unlockObjectRecord = function (objectName, reocrdId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0: return [4 /*yield*/, objectql.getObject(objectName).directUpdate(reocrdId, { locked: false })];
|
|
60
|
+
case 1:
|
|
61
|
+
_a.sent();
|
|
62
|
+
return [2 /*return*/];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}); };
|
|
66
|
+
var getProcessNodeApprover = function (instanceId, processNode, userSession, chooseApprover, isBack, record) { return __awaiter(void 0, void 0, void 0, function () {
|
|
67
|
+
var nodeApprover, processInstanceNodes, lastProcessInstanceNode, nodeHistroy, approver, _i, _a, roleId, dbRoles, role, submitted_by_1, spaceId_1, processInstance, assigned_approver_flow_role_ids_1, flowRoleKeys, _b, flowRoleKeys_1, flowRoleKey, dbFlowRole, dbFlowRoles, handlers, processInstance;
|
|
68
|
+
return __generator(this, function (_c) {
|
|
69
|
+
switch (_c.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
nodeApprover = [];
|
|
72
|
+
if (!isBack) return [3 /*break*/, 4];
|
|
73
|
+
return [4 /*yield*/, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['process_node', '=', processNode._id]], sort: "created desc" })];
|
|
74
|
+
case 1:
|
|
75
|
+
processInstanceNodes = _c.sent();
|
|
76
|
+
if (!!_.isEmpty(processInstanceNodes)) return [3 /*break*/, 3];
|
|
77
|
+
lastProcessInstanceNode = processInstanceNodes[0];
|
|
78
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").find({ filters: ['process_instance_node', '=', lastProcessInstanceNode._id] })];
|
|
79
|
+
case 2:
|
|
80
|
+
nodeHistroy = _c.sent();
|
|
81
|
+
_.each(nodeHistroy, function (item) {
|
|
82
|
+
nodeApprover.push(item.original_actor);
|
|
83
|
+
});
|
|
84
|
+
_c.label = 3;
|
|
85
|
+
case 3: return [3 /*break*/, 27];
|
|
86
|
+
case 4:
|
|
87
|
+
approver = processNode.approver;
|
|
88
|
+
if (!(approver === 'auto_assign')) return [3 /*break*/, 26];
|
|
89
|
+
if (!_.isEmpty(processNode.assigned_approver_users)) {
|
|
90
|
+
nodeApprover = nodeApprover.concat(processNode.assigned_approver_users);
|
|
54
91
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
if (!!_.isEmpty(processNode.assigned_approver_roles)) return [3 /*break*/, 10];
|
|
93
|
+
_i = 0, _a = processNode.assigned_approver_roles;
|
|
94
|
+
_c.label = 5;
|
|
95
|
+
case 5:
|
|
96
|
+
if (!(_i < _a.length)) return [3 /*break*/, 10];
|
|
97
|
+
roleId = _a[_i];
|
|
98
|
+
return [4 /*yield*/, objectql.getObject("roles").find({ filters: ['api_name', '=', roleId] })];
|
|
99
|
+
case 6:
|
|
100
|
+
dbRoles = _c.sent();
|
|
101
|
+
if (!(dbRoles && dbRoles.length > 0 && !_.isEmpty(dbRoles[0].users))) return [3 /*break*/, 7];
|
|
102
|
+
nodeApprover = nodeApprover.concat(dbRoles[0].users);
|
|
103
|
+
return [3 /*break*/, 9];
|
|
104
|
+
case 7: return [4 /*yield*/, objectql.getObject('roles').findOne(roleId)];
|
|
105
|
+
case 8:
|
|
106
|
+
role = _c.sent();
|
|
107
|
+
if (role && !_.isEmpty(role.users)) {
|
|
108
|
+
nodeApprover = nodeApprover.concat(role.users);
|
|
67
109
|
}
|
|
68
|
-
|
|
110
|
+
_c.label = 9;
|
|
111
|
+
case 9:
|
|
112
|
+
_i++;
|
|
113
|
+
return [3 /*break*/, 5];
|
|
114
|
+
case 10:
|
|
115
|
+
if (!!_.isEmpty(processNode.assigned_approver_flow_roles)) return [3 /*break*/, 21];
|
|
116
|
+
submitted_by_1 = userSession.userId;
|
|
117
|
+
spaceId_1 = userSession.spaceId;
|
|
118
|
+
if (!instanceId) return [3 /*break*/, 12];
|
|
119
|
+
return [4 /*yield*/, objectql.getObject("process_instance").findOne(instanceId)];
|
|
120
|
+
case 11:
|
|
121
|
+
processInstance = _c.sent();
|
|
122
|
+
submitted_by_1 = processInstance.submitted_by;
|
|
123
|
+
_c.label = 12;
|
|
124
|
+
case 12:
|
|
125
|
+
assigned_approver_flow_role_ids_1 = [];
|
|
126
|
+
flowRoleKeys = processNode.assigned_approver_flow_roles;
|
|
127
|
+
_b = 0, flowRoleKeys_1 = flowRoleKeys;
|
|
128
|
+
_c.label = 13;
|
|
129
|
+
case 13:
|
|
130
|
+
if (!(_b < flowRoleKeys_1.length)) return [3 /*break*/, 19];
|
|
131
|
+
flowRoleKey = flowRoleKeys_1[_b];
|
|
132
|
+
dbFlowRole = void 0;
|
|
133
|
+
return [4 /*yield*/, objectql.getObject("flow_roles").find({ filters: ['api_name', '=', flowRoleKey] })];
|
|
134
|
+
case 14:
|
|
135
|
+
dbFlowRoles = _c.sent();
|
|
136
|
+
if (!(dbFlowRoles && dbFlowRoles.length == 1)) return [3 /*break*/, 15];
|
|
137
|
+
dbFlowRole = dbFlowRoles[0];
|
|
138
|
+
return [3 /*break*/, 17];
|
|
139
|
+
case 15: return [4 /*yield*/, objectql.getObject("flow_roles").findOne(flowRoleKey)];
|
|
140
|
+
case 16:
|
|
141
|
+
dbFlowRole = _c.sent();
|
|
142
|
+
_c.label = 17;
|
|
143
|
+
case 17:
|
|
144
|
+
assigned_approver_flow_role_ids_1.push(dbFlowRole._id);
|
|
145
|
+
_c.label = 18;
|
|
146
|
+
case 18:
|
|
147
|
+
_b++;
|
|
148
|
+
return [3 /*break*/, 13];
|
|
149
|
+
case 19: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
69
150
|
Fiber(function () {
|
|
70
151
|
try {
|
|
71
|
-
|
|
72
|
-
resolve(
|
|
152
|
+
var handlers_1 = getHandlersManager.getHandlersByUserAndRoles(submitted_by_1, assigned_approver_flow_role_ids_1, spaceId_1);
|
|
153
|
+
resolve(handlers_1);
|
|
73
154
|
}
|
|
74
155
|
catch (error) {
|
|
75
156
|
reject(error);
|
|
76
157
|
}
|
|
77
158
|
}).run();
|
|
78
|
-
});
|
|
159
|
+
})];
|
|
160
|
+
case 20:
|
|
161
|
+
handlers = _c.sent();
|
|
79
162
|
nodeApprover = nodeApprover.concat(handlers);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
163
|
+
_c.label = 21;
|
|
164
|
+
case 21:
|
|
165
|
+
if (!!_.isEmpty(processNode.assigned_approver_user_field)) return [3 /*break*/, 25];
|
|
166
|
+
if (!instanceId) return [3 /*break*/, 24];
|
|
167
|
+
return [4 /*yield*/, objectql.getObject("process_instance").findOne(instanceId)];
|
|
168
|
+
case 22:
|
|
169
|
+
processInstance = _c.sent();
|
|
170
|
+
return [4 /*yield*/, objectql.getObject(processInstance.target_object.o).findOne(processInstance.target_object.ids[0])];
|
|
171
|
+
case 23:
|
|
172
|
+
record = _c.sent();
|
|
173
|
+
_c.label = 24;
|
|
174
|
+
case 24:
|
|
86
175
|
if (record) {
|
|
87
176
|
_.each(processNode.assigned_approver_user_field, function (fieldName) {
|
|
88
|
-
|
|
177
|
+
var fieldValue = record[fieldName];
|
|
89
178
|
if (_.isString(fieldValue)) {
|
|
90
179
|
fieldValue = [fieldValue];
|
|
91
180
|
}
|
|
@@ -94,107 +183,165 @@ const getProcessNodeApprover = async (instanceId, processNode, userSession, choo
|
|
|
94
183
|
}
|
|
95
184
|
});
|
|
96
185
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
186
|
+
_c.label = 25;
|
|
187
|
+
case 25: return [3 /*break*/, 27];
|
|
188
|
+
case 26:
|
|
189
|
+
if (approver === 'submitter_choose') {
|
|
190
|
+
if (chooseApprover) {
|
|
191
|
+
if (_.isString(chooseApprover)) {
|
|
192
|
+
return [2 /*return*/, [chooseApprover]];
|
|
193
|
+
}
|
|
194
|
+
else if (_.isArray(chooseApprover)) {
|
|
195
|
+
return [2 /*return*/, _.uniq(_.compact(chooseApprover))];
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new objectql_1.SteedosError('process_approval_error_invalidChooseApprover');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
throw new objectql_1.SteedosError('process_approval_error_needToChooseApprover');
|
|
203
|
+
}
|
|
109
204
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
throw new objectql_1.SteedosError('process_approval_error_needToChooseApprover');
|
|
113
|
-
}
|
|
205
|
+
_c.label = 27;
|
|
206
|
+
case 27: return [2 /*return*/, _.uniq(_.compact(nodeApprover))];
|
|
114
207
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
let instance = await objectql.getObject("process_instance").findOne(instanceId);
|
|
123
|
-
let name = '';
|
|
124
|
-
if (options.nodeId) {
|
|
125
|
-
const node = await objectql.getObject("process_node").findOne(options.nodeId);
|
|
126
|
-
if (node) {
|
|
127
|
-
name = node.label;
|
|
208
|
+
});
|
|
209
|
+
}); };
|
|
210
|
+
var getProcessNodes = function (processDefinitionId, spaceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
211
|
+
return __generator(this, function (_a) {
|
|
212
|
+
switch (_a.label) {
|
|
213
|
+
case 0: return [4 /*yield*/, objectql.getObject('process_node').find({ filters: [['process_definition', '=', processDefinitionId], ['space', '=', spaceId]], sort: "order asc" })];
|
|
214
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
128
215
|
}
|
|
129
|
-
}
|
|
130
|
-
let instanceHistory = await objectql.getObject("process_instance_history").insert({
|
|
131
|
-
name: name,
|
|
132
|
-
process_instance: instanceId,
|
|
133
|
-
target_object: instance.target_object,
|
|
134
|
-
step_status: status,
|
|
135
|
-
original_actor: options.originalActor || options.actor,
|
|
136
|
-
actor: options.actor,
|
|
137
|
-
comments: comment,
|
|
138
|
-
step_node: options.nodeId,
|
|
139
|
-
process_instance_node: options.instanceNodeId,
|
|
140
|
-
space: spaceId,
|
|
141
|
-
created_by: userSession.userId
|
|
142
216
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
217
|
+
}); };
|
|
218
|
+
var addInstanceHistory = function (spaceId, instanceId, status, comment, options, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
+
var instance, name, node, instanceHistory;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance").findOne(instanceId)];
|
|
223
|
+
case 1:
|
|
224
|
+
instance = _a.sent();
|
|
225
|
+
name = '';
|
|
226
|
+
if (!options.nodeId) return [3 /*break*/, 3];
|
|
227
|
+
return [4 /*yield*/, objectql.getObject("process_node").findOne(options.nodeId)];
|
|
228
|
+
case 2:
|
|
229
|
+
node = _a.sent();
|
|
230
|
+
if (node) {
|
|
231
|
+
name = node.label;
|
|
232
|
+
}
|
|
233
|
+
_a.label = 3;
|
|
234
|
+
case 3: return [4 /*yield*/, objectql.getObject("process_instance_history").insert({
|
|
235
|
+
name: name,
|
|
236
|
+
process_instance: instanceId,
|
|
237
|
+
target_object: instance.target_object,
|
|
238
|
+
step_status: status,
|
|
239
|
+
original_actor: options.originalActor || options.actor,
|
|
240
|
+
actor: options.actor,
|
|
241
|
+
comments: comment,
|
|
242
|
+
step_node: options.nodeId,
|
|
243
|
+
process_instance_node: options.instanceNodeId,
|
|
244
|
+
space: spaceId,
|
|
245
|
+
created_by: userSession.userId
|
|
246
|
+
})];
|
|
247
|
+
case 4:
|
|
248
|
+
instanceHistory = _a.sent();
|
|
249
|
+
if (!(status === 'approved' || status === 'rejected')) return [3 /*break*/, 6];
|
|
250
|
+
return [4 /*yield*/, handleProcessInstance(instanceHistory.process_instance, status, userSession)];
|
|
251
|
+
case 5:
|
|
252
|
+
_a.sent();
|
|
253
|
+
_a.label = 6;
|
|
254
|
+
case 6:
|
|
255
|
+
if (!(status === 'pending')) return [3 /*break*/, 8];
|
|
256
|
+
return [4 /*yield*/, (0, notifications_1.sendNotifications)(instance.created_by, options.actor, { instanceHistory: instanceHistory, status: status, instance: instance })];
|
|
257
|
+
case 7:
|
|
258
|
+
_a.sent();
|
|
259
|
+
_a.label = 8;
|
|
260
|
+
case 8: return [2 /*return*/];
|
|
261
|
+
}
|
|
161
262
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
263
|
+
}); };
|
|
264
|
+
var addInstanceNode = function (instanceId, node, userSession, nodeApprover) { return __awaiter(void 0, void 0, void 0, function () {
|
|
265
|
+
var nodeId, nodeName, instanceNode, _i, nodeApprover_1, actor;
|
|
266
|
+
return __generator(this, function (_a) {
|
|
267
|
+
switch (_a.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
nodeId = node._id;
|
|
270
|
+
nodeName = node.label;
|
|
271
|
+
return [4 /*yield*/, objectql.getObject("process_instance_node").insert({
|
|
272
|
+
process_instance: instanceId,
|
|
273
|
+
process_node: nodeId,
|
|
274
|
+
process_node_name: nodeName,
|
|
275
|
+
node_status: 'pending',
|
|
276
|
+
space: userSession.spaceId,
|
|
277
|
+
created_by: userSession.userId
|
|
278
|
+
})];
|
|
279
|
+
case 1:
|
|
280
|
+
instanceNode = _a.sent();
|
|
281
|
+
_i = 0, nodeApprover_1 = nodeApprover;
|
|
282
|
+
_a.label = 2;
|
|
283
|
+
case 2:
|
|
284
|
+
if (!(_i < nodeApprover_1.length)) return [3 /*break*/, 5];
|
|
285
|
+
actor = nodeApprover_1[_i];
|
|
286
|
+
return [4 /*yield*/, addInstanceHistory(userSession.spaceId, instanceId, 'pending', null, { nodeId: nodeId, actor: actor, originalActor: actor, submitted_by: userSession.userId, instanceNodeId: instanceNode._id }, userSession)];
|
|
287
|
+
case 3:
|
|
288
|
+
_a.sent();
|
|
289
|
+
_a.label = 4;
|
|
290
|
+
case 4:
|
|
291
|
+
_i++;
|
|
292
|
+
return [3 /*break*/, 2];
|
|
293
|
+
case 5: return [2 /*return*/];
|
|
173
294
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return
|
|
188
|
-
|
|
295
|
+
});
|
|
296
|
+
}); };
|
|
297
|
+
var getNextNode = function (nodes, index, objectName, recordId, userSession) {
|
|
298
|
+
if (index === void 0) { index = 0; }
|
|
299
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
300
|
+
var spaceId, currentUserId, node, canEntry;
|
|
301
|
+
return __generator(this, function (_a) {
|
|
302
|
+
switch (_a.label) {
|
|
303
|
+
case 0:
|
|
304
|
+
spaceId = userSession.spaceId;
|
|
305
|
+
currentUserId = userSession.userId;
|
|
306
|
+
node = nodes[index];
|
|
307
|
+
if (!node) return [3 /*break*/, 6];
|
|
308
|
+
if (!node.filtrad) return [3 /*break*/, 1];
|
|
309
|
+
return [2 /*return*/, node];
|
|
310
|
+
case 1: return [4 /*yield*/, objectql.computeFormula(node.entry_criteria, objectName, recordId, currentUserId, spaceId)];
|
|
311
|
+
case 2:
|
|
312
|
+
canEntry = _a.sent();
|
|
313
|
+
if (!canEntry) return [3 /*break*/, 3];
|
|
314
|
+
return [2 /*return*/, node];
|
|
315
|
+
case 3:
|
|
316
|
+
if (!(node.if_criteria_not_met === 'skip')) return [3 /*break*/, 5];
|
|
317
|
+
return [4 /*yield*/, getNextNode(nodes, index + 1, objectName, recordId, userSession)];
|
|
318
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
319
|
+
case 5:
|
|
320
|
+
if (node.if_criteria_not_met === 'reject') {
|
|
321
|
+
return [2 /*return*/, { to_final_rejection: true }];
|
|
322
|
+
}
|
|
323
|
+
else if (node.if_criteria_not_met === 'approve') {
|
|
324
|
+
return [2 /*return*/, { to_final_approval: true }];
|
|
325
|
+
}
|
|
326
|
+
_a.label = 6;
|
|
327
|
+
case 6: return [2 /*return*/];
|
|
189
328
|
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
const toNextNode = async (instanceId, node, nextApprovers, userSession) => {
|
|
194
|
-
if (node) {
|
|
195
|
-
await addInstanceNode(instanceId, node, userSession, nextApprovers);
|
|
196
|
-
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
197
331
|
};
|
|
332
|
+
var toNextNode = function (instanceId, node, nextApprovers, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
333
|
+
return __generator(this, function (_a) {
|
|
334
|
+
switch (_a.label) {
|
|
335
|
+
case 0:
|
|
336
|
+
if (!node) return [3 /*break*/, 2];
|
|
337
|
+
return [4 /*yield*/, addInstanceNode(instanceId, node, userSession, nextApprovers)];
|
|
338
|
+
case 1:
|
|
339
|
+
_a.sent();
|
|
340
|
+
_a.label = 2;
|
|
341
|
+
case 2: return [2 /*return*/];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}); };
|
|
198
345
|
//TODO nextApprovers
|
|
199
346
|
// const toNextNode = async (instanceId: string, comment: string, nodes: any, index: number = 0, objectName: string, recordId: string, userSession: any, nextApprovers?)=>{
|
|
200
347
|
// let spaceId = userSession.spaceId;
|
|
@@ -222,17 +369,23 @@ const toNextNode = async (instanceId, node, nextApprovers, userSession) => {
|
|
|
222
369
|
// }
|
|
223
370
|
// }
|
|
224
371
|
// }
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
372
|
+
var getPreviousNode = function (instanceId, currentNode, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
373
|
+
var previousInstanceNodes, previousInstanceNode, previousNode;
|
|
374
|
+
return __generator(this, function (_a) {
|
|
375
|
+
switch (_a.label) {
|
|
376
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc' })];
|
|
377
|
+
case 1:
|
|
378
|
+
previousInstanceNodes = _a.sent();
|
|
379
|
+
if (!!_.isEmpty(previousInstanceNodes)) return [3 /*break*/, 3];
|
|
380
|
+
previousInstanceNode = previousInstanceNodes[0];
|
|
381
|
+
return [4 /*yield*/, objectql.getObject("process_node").findOne(previousInstanceNode.process_node)];
|
|
382
|
+
case 2:
|
|
383
|
+
previousNode = _a.sent();
|
|
384
|
+
return [2 /*return*/, previousNode];
|
|
385
|
+
case 3: throw new objectql_1.SteedosError('not find previous node');
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}); };
|
|
236
389
|
// const toPreviousNode = async (instanceId: string, currentNode: any, userSession: any)=>{
|
|
237
390
|
// const previousInstanceNodes = await objectql.getObject("process_instance_node").find({filters: [['process_instance', '=', instanceId], ['process_node', '!=', currentNode._id]], sort: 'created desc'});
|
|
238
391
|
// if(!_.isEmpty(previousInstanceNodes)){
|
|
@@ -244,88 +397,150 @@ const getPreviousNode = async (instanceId, currentNode, userSession) => {
|
|
|
244
397
|
// }
|
|
245
398
|
// }
|
|
246
399
|
//TODO 处理提交权限
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
400
|
+
var getObjectProcessDefinition = function (objectName, recordId, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
401
|
+
var spaceId, currentUserId, processes, process, _i, processes_1, _process, canEntry;
|
|
402
|
+
return __generator(this, function (_a) {
|
|
403
|
+
switch (_a.label) {
|
|
404
|
+
case 0:
|
|
405
|
+
spaceId = userSession.spaceId;
|
|
406
|
+
currentUserId = userSession.userId;
|
|
407
|
+
return [4 /*yield*/, objectql.getObject('process_definition').find({ filters: [['object_name', '=', objectName], ['space', '=', spaceId], ['active', '=', true]], sort: "order asc" })];
|
|
408
|
+
case 1:
|
|
409
|
+
processes = _a.sent();
|
|
410
|
+
if (processes.length < 1) {
|
|
411
|
+
return [2 /*return*/, null];
|
|
412
|
+
}
|
|
413
|
+
process = null;
|
|
414
|
+
_i = 0, processes_1 = processes;
|
|
415
|
+
_a.label = 2;
|
|
416
|
+
case 2:
|
|
417
|
+
if (!(_i < processes_1.length)) return [3 /*break*/, 5];
|
|
418
|
+
_process = processes_1[_i];
|
|
419
|
+
return [4 /*yield*/, objectql.computeFormula(_process.entry_criteria, objectName, recordId, currentUserId, spaceId)];
|
|
420
|
+
case 3:
|
|
421
|
+
canEntry = _a.sent();
|
|
422
|
+
if (canEntry) {
|
|
423
|
+
process = _process;
|
|
424
|
+
return [3 /*break*/, 5];
|
|
425
|
+
}
|
|
426
|
+
_a.label = 4;
|
|
427
|
+
case 4:
|
|
428
|
+
_i++;
|
|
429
|
+
return [3 /*break*/, 2];
|
|
430
|
+
case 5: return [2 /*return*/, process];
|
|
261
431
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
};
|
|
432
|
+
});
|
|
433
|
+
}); };
|
|
265
434
|
exports.getObjectProcessDefinition = getObjectProcessDefinition;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
435
|
+
var recordSubmit = function (processDefinitionId, objectName, recordId, userSession, comment, chooseApprover) { return __awaiter(void 0, void 0, void 0, function () {
|
|
436
|
+
var pendingInstanceCount, nodes, nextNode, to_final_rejection, to_final_approval, approver, record, instance, options, options;
|
|
437
|
+
return __generator(this, function (_a) {
|
|
438
|
+
switch (_a.label) {
|
|
439
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance").count({ filters: [['target_object.o', '=', objectName], ['target_object.ids', '=', recordId], ['status', '=', 'pending']] })];
|
|
440
|
+
case 1:
|
|
441
|
+
pendingInstanceCount = _a.sent();
|
|
442
|
+
if (pendingInstanceCount > 0) {
|
|
443
|
+
throw new objectql_1.SteedosError('process_approval_error_processInstancePending');
|
|
444
|
+
}
|
|
445
|
+
return [4 /*yield*/, getProcessNodes(processDefinitionId, userSession.spaceId)];
|
|
446
|
+
case 2:
|
|
447
|
+
nodes = _a.sent();
|
|
448
|
+
return [4 /*yield*/, getNextNode(nodes, 0, objectName, recordId, userSession)];
|
|
449
|
+
case 3:
|
|
450
|
+
nextNode = _a.sent();
|
|
451
|
+
to_final_rejection = false;
|
|
452
|
+
to_final_approval = false;
|
|
453
|
+
if (nextNode.to_final_rejection) {
|
|
454
|
+
to_final_rejection = true;
|
|
455
|
+
}
|
|
456
|
+
else if (nextNode.to_final_approval) {
|
|
457
|
+
to_final_approval = true;
|
|
458
|
+
}
|
|
459
|
+
approver = null;
|
|
460
|
+
if (!(!to_final_rejection && !to_final_rejection)) return [3 /*break*/, 6];
|
|
461
|
+
return [4 /*yield*/, objectql.getObject(objectName).findOne(recordId)];
|
|
462
|
+
case 4:
|
|
463
|
+
record = _a.sent();
|
|
464
|
+
return [4 /*yield*/, getProcessNodeApprover(null, nextNode, userSession, chooseApprover, false, record)];
|
|
465
|
+
case 5:
|
|
466
|
+
approver = _a.sent();
|
|
467
|
+
_a.label = 6;
|
|
468
|
+
case 6: return [4 /*yield*/, objectql.getObject("process_instance").insert({
|
|
469
|
+
process_definition: processDefinitionId,
|
|
470
|
+
target_object: {
|
|
471
|
+
"o": objectName,
|
|
472
|
+
"ids": [recordId]
|
|
473
|
+
},
|
|
474
|
+
status: "pending",
|
|
475
|
+
space: userSession.spaceId,
|
|
476
|
+
submitted_by: userSession.userId,
|
|
477
|
+
created_by: userSession.userId
|
|
478
|
+
})];
|
|
479
|
+
case 7:
|
|
480
|
+
instance = _a.sent();
|
|
481
|
+
return [4 /*yield*/, lockObjectRecord(objectName, recordId)];
|
|
482
|
+
case 8:
|
|
483
|
+
_a.sent();
|
|
484
|
+
return [4 /*yield*/, (0, platform_action_manager_1.runProcessAction)(processDefinitionId, 'initial_submission', recordId, userSession)];
|
|
485
|
+
case 9:
|
|
486
|
+
_a.sent();
|
|
487
|
+
return [4 /*yield*/, addInstanceHistory(userSession.spaceId, instance._id, "started", comment, { actor: userSession.userId }, userSession)];
|
|
488
|
+
case 10:
|
|
489
|
+
_a.sent();
|
|
490
|
+
if (!to_final_rejection) return [3 /*break*/, 12];
|
|
491
|
+
options = { actor: userSession.userId };
|
|
492
|
+
return [4 /*yield*/, addInstanceHistory(userSession.spaceId, instance._id, "rejected", comment, options, userSession)];
|
|
493
|
+
case 11:
|
|
494
|
+
_a.sent();
|
|
495
|
+
return [3 /*break*/, 16];
|
|
496
|
+
case 12:
|
|
497
|
+
if (!to_final_approval) return [3 /*break*/, 14];
|
|
498
|
+
options = { actor: userSession.userId };
|
|
499
|
+
return [4 /*yield*/, addInstanceHistory(userSession.spaceId, instance._id, "approved", comment, options, userSession)];
|
|
500
|
+
case 13:
|
|
501
|
+
_a.sent();
|
|
502
|
+
return [3 /*break*/, 16];
|
|
503
|
+
case 14: return [4 /*yield*/, toNextNode(instance._id, nextNode, approver, userSession)];
|
|
504
|
+
case 15:
|
|
505
|
+
_a.sent();
|
|
506
|
+
_a.label = 16;
|
|
507
|
+
case 16: return [2 /*return*/];
|
|
508
|
+
}
|
|
296
509
|
});
|
|
297
|
-
|
|
298
|
-
await (0, platform_action_manager_1.runProcessAction)(processDefinitionId, 'initial_submission', recordId, userSession);
|
|
299
|
-
await addInstanceHistory(userSession.spaceId, instance._id, "started", comment, { actor: userSession.userId }, userSession);
|
|
300
|
-
if (to_final_rejection) {
|
|
301
|
-
let options = { actor: userSession.userId };
|
|
302
|
-
await addInstanceHistory(userSession.spaceId, instance._id, "rejected", comment, options, userSession);
|
|
303
|
-
}
|
|
304
|
-
else if (to_final_approval) {
|
|
305
|
-
let options = { actor: userSession.userId };
|
|
306
|
-
await addInstanceHistory(userSession.spaceId, instance._id, "approved", comment, options, userSession);
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
await toNextNode(instance._id, nextNode, approver, userSession);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
510
|
+
}); };
|
|
312
511
|
exports.recordSubmit = recordSubmit;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return
|
|
316
|
-
|
|
512
|
+
var getReocrdProcessInstance = function (objectName, recordId, status, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
513
|
+
var spaceId;
|
|
514
|
+
return __generator(this, function (_a) {
|
|
515
|
+
switch (_a.label) {
|
|
516
|
+
case 0:
|
|
517
|
+
spaceId = userSession.spaceId;
|
|
518
|
+
return [4 /*yield*/, objectql.getObject("process_instance").find({ filters: [['space', '=', spaceId], ['status', '=', status], ['target_object.o', '=', objectName], ['target_object.ids', '=', recordId]] })];
|
|
519
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}); };
|
|
317
523
|
exports.getReocrdProcessInstance = getReocrdProcessInstance;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
};
|
|
524
|
+
var getProcessInstanceWorkitem = function (instanceHistoryId, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
525
|
+
var spaceId, userId, workitme;
|
|
526
|
+
return __generator(this, function (_a) {
|
|
527
|
+
switch (_a.label) {
|
|
528
|
+
case 0:
|
|
529
|
+
spaceId = userSession.spaceId;
|
|
530
|
+
userId = userSession.userId;
|
|
531
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").find({ filters: [['_id', '=', instanceHistoryId], ['step_status', '=', 'pending'], ['actor', '=', userId], ['space', '=', spaceId]] })];
|
|
532
|
+
case 1:
|
|
533
|
+
workitme = _a.sent();
|
|
534
|
+
if (workitme.length > 0) {
|
|
535
|
+
return [2 /*return*/, workitme[0]];
|
|
536
|
+
}
|
|
537
|
+
return [2 /*return*/];
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}); };
|
|
326
541
|
exports.getProcessInstanceWorkitem = getProcessInstanceWorkitem;
|
|
327
|
-
|
|
328
|
-
|
|
542
|
+
var getProcessActionWhenByStatus = function (processStatus) {
|
|
543
|
+
var when = '';
|
|
329
544
|
if (processStatus === 'approved') {
|
|
330
545
|
when = 'final_approval';
|
|
331
546
|
}
|
|
@@ -337,8 +552,8 @@ const getProcessActionWhenByStatus = (processStatus) => {
|
|
|
337
552
|
}
|
|
338
553
|
return when;
|
|
339
554
|
};
|
|
340
|
-
|
|
341
|
-
|
|
555
|
+
var getProcessNodeActionWhenByStatus = function (processStatus) {
|
|
556
|
+
var when = '';
|
|
342
557
|
if (processStatus === 'approved') {
|
|
343
558
|
when = 'approval';
|
|
344
559
|
}
|
|
@@ -361,164 +576,321 @@ const getProcessNodeActionWhenByStatus = (processStatus) => {
|
|
|
361
576
|
// }
|
|
362
577
|
// }
|
|
363
578
|
//TODO 编写trigger 处理elapsed_time
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
579
|
+
var handleProcessInstance = function (instanceId, processStatus, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
580
|
+
var otherPendingInstanceNodeCount, pInstance, process_1, when;
|
|
581
|
+
return __generator(this, function (_a) {
|
|
582
|
+
switch (_a.label) {
|
|
583
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_node").count({ filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']] })];
|
|
584
|
+
case 1:
|
|
585
|
+
otherPendingInstanceNodeCount = _a.sent();
|
|
586
|
+
if (!(otherPendingInstanceNodeCount === 0)) return [3 /*break*/, 18];
|
|
587
|
+
return [4 /*yield*/, objectql.getObject("process_instance").update(instanceId, { status: processStatus, completed_date: new Date(), last_actor: userSession.userId })];
|
|
588
|
+
case 2:
|
|
589
|
+
pInstance = _a.sent();
|
|
590
|
+
if (!(processStatus === 'removed')) return [3 /*break*/, 4];
|
|
591
|
+
return [4 /*yield*/, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
592
|
+
case 3:
|
|
593
|
+
_a.sent();
|
|
594
|
+
return [3 /*break*/, 14];
|
|
595
|
+
case 4: return [4 /*yield*/, objectql.getObject("process_definition").findOne(pInstance.process_definition)];
|
|
596
|
+
case 5:
|
|
597
|
+
process_1 = _a.sent();
|
|
598
|
+
if (!(processStatus === 'approved')) return [3 /*break*/, 10];
|
|
599
|
+
if (!(process_1.final_approval_record_lock === 'unlock')) return [3 /*break*/, 7];
|
|
600
|
+
return [4 /*yield*/, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
601
|
+
case 6:
|
|
602
|
+
_a.sent();
|
|
603
|
+
return [3 /*break*/, 9];
|
|
604
|
+
case 7: return [4 /*yield*/, lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
605
|
+
case 8:
|
|
606
|
+
_a.sent();
|
|
607
|
+
_a.label = 9;
|
|
608
|
+
case 9: return [3 /*break*/, 14];
|
|
609
|
+
case 10:
|
|
610
|
+
if (!(processStatus === 'rejected')) return [3 /*break*/, 14];
|
|
611
|
+
if (!(process_1.final_rejection_record_lock === 'unlock')) return [3 /*break*/, 12];
|
|
612
|
+
return [4 /*yield*/, unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
613
|
+
case 11:
|
|
614
|
+
_a.sent();
|
|
615
|
+
return [3 /*break*/, 14];
|
|
616
|
+
case 12: return [4 /*yield*/, lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0])];
|
|
617
|
+
case 13:
|
|
618
|
+
_a.sent();
|
|
619
|
+
_a.label = 14;
|
|
620
|
+
case 14:
|
|
621
|
+
when = getProcessActionWhenByStatus(processStatus);
|
|
622
|
+
if (!when) return [3 /*break*/, 16];
|
|
623
|
+
return [4 /*yield*/, (0, platform_action_manager_1.runProcessAction)(pInstance.process_definition, when, pInstance.target_object.ids[0], userSession)];
|
|
624
|
+
case 15:
|
|
625
|
+
_a.sent();
|
|
626
|
+
_a.label = 16;
|
|
627
|
+
case 16:
|
|
628
|
+
if (!(['approved', 'rejected'].indexOf(processStatus) > -1)) return [3 /*break*/, 18];
|
|
629
|
+
return [4 /*yield*/, (0, notifications_1.sendNotifications)(pInstance.created_by, pInstance.created_by, { status: processStatus, instance: pInstance })];
|
|
630
|
+
case 17:
|
|
631
|
+
_a.sent();
|
|
632
|
+
_a.label = 18;
|
|
633
|
+
case 18: return [2 /*return*/];
|
|
370
634
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
await unlockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
await lockObjectRecord(pInstance.target_object.o, pInstance.target_object.ids[0]);
|
|
635
|
+
});
|
|
636
|
+
}); };
|
|
637
|
+
var getCurrentInstanceNode = function (instanceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
638
|
+
var pendingNodes, currentNode;
|
|
639
|
+
return __generator(this, function (_a) {
|
|
640
|
+
switch (_a.label) {
|
|
641
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']] })];
|
|
642
|
+
case 1:
|
|
643
|
+
pendingNodes = _a.sent();
|
|
644
|
+
currentNode = null;
|
|
645
|
+
if (pendingNodes.length > 0) {
|
|
646
|
+
currentNode = pendingNodes[0];
|
|
387
647
|
}
|
|
388
|
-
|
|
648
|
+
return [2 /*return*/, currentNode];
|
|
389
649
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
650
|
+
});
|
|
651
|
+
}); };
|
|
652
|
+
var getProcessInstance = function (instanceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
653
|
+
return __generator(this, function (_a) {
|
|
654
|
+
switch (_a.label) {
|
|
655
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance").findOne(instanceId)];
|
|
656
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
393
657
|
}
|
|
394
|
-
|
|
395
|
-
|
|
658
|
+
});
|
|
659
|
+
}); };
|
|
660
|
+
var getProcessNode = function (processNodeId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
661
|
+
return __generator(this, function (_a) {
|
|
662
|
+
switch (_a.label) {
|
|
663
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_node").findOne(processNodeId)];
|
|
664
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
396
665
|
}
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
const getCurrentInstanceNode = async (instanceId) => {
|
|
400
|
-
const pendingNodes = await objectql.getObject("process_instance_node").find({ filters: [['process_instance', '=', instanceId], ['node_status', '=', 'pending']] });
|
|
401
|
-
let currentNode = null;
|
|
402
|
-
if (pendingNodes.length > 0) {
|
|
403
|
-
currentNode = pendingNodes[0];
|
|
404
|
-
}
|
|
405
|
-
return currentNode;
|
|
406
|
-
};
|
|
407
|
-
const getProcessInstance = async (instanceId) => {
|
|
408
|
-
return await objectql.getObject("process_instance").findOne(instanceId);
|
|
409
|
-
};
|
|
410
|
-
const getProcessNode = async (processNodeId) => {
|
|
411
|
-
return await objectql.getObject("process_node").findOne(processNodeId);
|
|
412
|
-
};
|
|
666
|
+
});
|
|
667
|
+
}); };
|
|
413
668
|
//TODO 编写trigger 处理elapsed_time
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
669
|
+
var handleProcessInstanceNode = function (instanceId, currentInstanceNode, processStatus, nextNodeOptions, userSession) { return __awaiter(void 0, void 0, void 0, function () {
|
|
670
|
+
var otherPendingInstanceHistoryCount, finalProcessStatus, when, instance, to_final_rejection, to_final_approval;
|
|
671
|
+
return __generator(this, function (_a) {
|
|
672
|
+
switch (_a.label) {
|
|
673
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_history").count({ filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']] })];
|
|
674
|
+
case 1:
|
|
675
|
+
otherPendingInstanceHistoryCount = _a.sent();
|
|
676
|
+
if (!(otherPendingInstanceHistoryCount === 0)) return [3 /*break*/, 11];
|
|
677
|
+
finalProcessStatus = processStatus;
|
|
678
|
+
return [4 /*yield*/, objectql.getObject("process_instance_node").updateMany([['process_instance', '=', instanceId], ['node_status', '=', 'pending']], { node_status: processStatus, completed_date: new Date(), last_actor: userSession.userId })];
|
|
679
|
+
case 2:
|
|
680
|
+
_a.sent();
|
|
681
|
+
when = getProcessNodeActionWhenByStatus(processStatus);
|
|
682
|
+
if (!when) return [3 /*break*/, 5];
|
|
683
|
+
return [4 /*yield*/, objectql.getObject("process_instance").findOne(instanceId)];
|
|
684
|
+
case 3:
|
|
685
|
+
instance = _a.sent();
|
|
686
|
+
return [4 /*yield*/, (0, platform_action_manager_1.runProcessNodeAction)(currentInstanceNode.process_node, when, instance.target_object.ids[0], userSession)];
|
|
687
|
+
case 4:
|
|
688
|
+
_a.sent();
|
|
689
|
+
_a.label = 5;
|
|
690
|
+
case 5:
|
|
691
|
+
if (!nextNodeOptions) return [3 /*break*/, 9];
|
|
692
|
+
to_final_rejection = false;
|
|
693
|
+
to_final_approval = false;
|
|
694
|
+
if (nextNodeOptions.node.to_final_rejection) {
|
|
695
|
+
to_final_rejection = true;
|
|
696
|
+
finalProcessStatus = 'rejected';
|
|
697
|
+
}
|
|
698
|
+
else if (nextNodeOptions.node.to_final_approval) {
|
|
699
|
+
to_final_approval = true;
|
|
700
|
+
finalProcessStatus = 'approved';
|
|
701
|
+
}
|
|
702
|
+
if (!to_final_rejection) return [3 /*break*/, 6];
|
|
703
|
+
return [3 /*break*/, 9];
|
|
704
|
+
case 6:
|
|
705
|
+
if (!to_final_approval) return [3 /*break*/, 7];
|
|
706
|
+
return [3 /*break*/, 9];
|
|
707
|
+
case 7: return [4 /*yield*/, toNextNode(instanceId, nextNodeOptions.node, nextNodeOptions.approve, userSession)];
|
|
708
|
+
case 8:
|
|
709
|
+
_a.sent();
|
|
710
|
+
_a.label = 9;
|
|
711
|
+
case 9: return [4 /*yield*/, handleProcessInstance(instanceId, finalProcessStatus, userSession)];
|
|
712
|
+
case 10:
|
|
713
|
+
_a.sent();
|
|
714
|
+
_a.label = 11;
|
|
715
|
+
case 11: return [2 /*return*/];
|
|
423
716
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
else if (nextNodeOptions.node.to_final_approval) {
|
|
432
|
-
to_final_approval = true;
|
|
433
|
-
finalProcessStatus = 'approved';
|
|
434
|
-
}
|
|
435
|
-
if (to_final_rejection) {
|
|
436
|
-
}
|
|
437
|
-
else if (to_final_approval) {
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
await toNextNode(instanceId, nextNodeOptions.node, nextNodeOptions.approve, userSession);
|
|
441
|
-
}
|
|
717
|
+
});
|
|
718
|
+
}); };
|
|
719
|
+
var getInstanceHistory = function (instanceHistoryId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
720
|
+
return __generator(this, function (_a) {
|
|
721
|
+
switch (_a.label) {
|
|
722
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_history").findOne(instanceHistoryId)];
|
|
723
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
442
724
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
return await objectql.getObject("process_instance_history").count({ filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']] });
|
|
451
|
-
};
|
|
452
|
-
const handleProcessInstanceWorkitem = async (currentInstanceNode, processStatus, instanceHistoryId, userSession, comment, nextNodeOptions) => {
|
|
453
|
-
let instanceHistory = await getInstanceHistory(instanceHistoryId);
|
|
454
|
-
if (processStatus === 'rejected' || processStatus === 'approved') {
|
|
455
|
-
await objectql.getObject("process_instance_history").update(instanceHistoryId, { step_status: processStatus, comments: comment, actor: userSession.userId });
|
|
456
|
-
let when_multiple_approvers = 'first_response';
|
|
457
|
-
if (instanceHistory.step_node) {
|
|
458
|
-
let processNode = await objectql.getObject("process_node").findOne(instanceHistory.step_node);
|
|
459
|
-
if (processNode && processNode.when_multiple_approvers) {
|
|
460
|
-
when_multiple_approvers = processNode.when_multiple_approvers;
|
|
461
|
-
}
|
|
725
|
+
});
|
|
726
|
+
}); };
|
|
727
|
+
var getPendingInstanceHistoryCount = function (instanceId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
728
|
+
return __generator(this, function (_a) {
|
|
729
|
+
switch (_a.label) {
|
|
730
|
+
case 0: return [4 /*yield*/, objectql.getObject("process_instance_history").count({ filters: [['process_instance', '=', instanceId], ['step_status', '=', 'pending']] })];
|
|
731
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
462
732
|
}
|
|
463
|
-
|
|
464
|
-
|
|
733
|
+
});
|
|
734
|
+
}); };
|
|
735
|
+
var handleProcessInstanceWorkitem = function (currentInstanceNode, processStatus, instanceHistoryId, userSession, comment, nextNodeOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
736
|
+
var instanceHistory, when_multiple_approvers, processNode;
|
|
737
|
+
return __generator(this, function (_a) {
|
|
738
|
+
switch (_a.label) {
|
|
739
|
+
case 0: return [4 /*yield*/, getInstanceHistory(instanceHistoryId)];
|
|
740
|
+
case 1:
|
|
741
|
+
instanceHistory = _a.sent();
|
|
742
|
+
if (!(processStatus === 'rejected' || processStatus === 'approved')) return [3 /*break*/, 6];
|
|
743
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").update(instanceHistoryId, { step_status: processStatus, comments: comment, actor: userSession.userId })];
|
|
744
|
+
case 2:
|
|
745
|
+
_a.sent();
|
|
746
|
+
when_multiple_approvers = 'first_response';
|
|
747
|
+
if (!instanceHistory.step_node) return [3 /*break*/, 4];
|
|
748
|
+
return [4 /*yield*/, objectql.getObject("process_node").findOne(instanceHistory.step_node)];
|
|
749
|
+
case 3:
|
|
750
|
+
processNode = _a.sent();
|
|
751
|
+
if (processNode && processNode.when_multiple_approvers) {
|
|
752
|
+
when_multiple_approvers = processNode.when_multiple_approvers;
|
|
753
|
+
}
|
|
754
|
+
_a.label = 4;
|
|
755
|
+
case 4:
|
|
756
|
+
if (!(when_multiple_approvers === 'first_response' || (when_multiple_approvers === 'unanimous' && processStatus === 'rejected'))) return [3 /*break*/, 6];
|
|
757
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").updateMany([['_id', '!=', instanceHistory._id], ['process_instance', '=', instanceHistory.process_instance], ['step_status', '=', 'pending']], { step_status: 'no_response' })];
|
|
758
|
+
case 5:
|
|
759
|
+
_a.sent();
|
|
760
|
+
_a.label = 6;
|
|
761
|
+
case 6: return [4 /*yield*/, handleProcessInstanceNode(instanceHistory.process_instance, currentInstanceNode, processStatus, nextNodeOptions, userSession)];
|
|
762
|
+
case 7:
|
|
763
|
+
_a.sent();
|
|
764
|
+
return [2 /*return*/];
|
|
465
765
|
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
766
|
+
});
|
|
767
|
+
}); };
|
|
768
|
+
var processInstanceWorkitemApprove = function (instanceHistoryId, userSession, comment, chooseApprover) { return __awaiter(void 0, void 0, void 0, function () {
|
|
769
|
+
var nextNodeOptions, instanceHistory, instanceId, currentInstanceNode, instance, currentProcessNode, nodes, index, _a, nextNode, _b;
|
|
770
|
+
return __generator(this, function (_c) {
|
|
771
|
+
switch (_c.label) {
|
|
772
|
+
case 0:
|
|
773
|
+
nextNodeOptions = null;
|
|
774
|
+
return [4 /*yield*/, getInstanceHistory(instanceHistoryId)];
|
|
775
|
+
case 1:
|
|
776
|
+
instanceHistory = _c.sent();
|
|
777
|
+
instanceId = instanceHistory.process_instance;
|
|
778
|
+
return [4 /*yield*/, getCurrentInstanceNode(instanceId)];
|
|
779
|
+
case 2:
|
|
780
|
+
currentInstanceNode = _c.sent();
|
|
781
|
+
return [4 /*yield*/, getProcessInstance(instanceId)];
|
|
782
|
+
case 3:
|
|
783
|
+
instance = _c.sent();
|
|
784
|
+
return [4 /*yield*/, getProcessNode(instanceHistory.step_node)];
|
|
785
|
+
case 4:
|
|
786
|
+
currentProcessNode = _c.sent();
|
|
787
|
+
return [4 /*yield*/, getProcessNodes(instance.process_definition, userSession.spaceId)];
|
|
788
|
+
case 5:
|
|
789
|
+
nodes = _c.sent();
|
|
790
|
+
index = _.findIndex(nodes, function (item) { return item._id === currentInstanceNode.process_node; });
|
|
791
|
+
_a = currentProcessNode.when_multiple_approvers === 'first_response';
|
|
792
|
+
if (_a) return [3 /*break*/, 7];
|
|
793
|
+
return [4 /*yield*/, getPendingInstanceHistoryCount(instanceId)];
|
|
794
|
+
case 6:
|
|
795
|
+
_a = (_c.sent()) < 2;
|
|
796
|
+
_c.label = 7;
|
|
797
|
+
case 7:
|
|
798
|
+
if (!_a) return [3 /*break*/, 10];
|
|
799
|
+
return [4 /*yield*/, getNextNode(nodes, index + 1, instance.target_object.o, instance.target_object.ids[0], userSession)];
|
|
800
|
+
case 8:
|
|
801
|
+
nextNode = _c.sent();
|
|
802
|
+
if (!nextNode) return [3 /*break*/, 10];
|
|
803
|
+
nextNodeOptions = {};
|
|
804
|
+
nextNodeOptions.node = nextNode;
|
|
805
|
+
_b = nextNodeOptions;
|
|
806
|
+
return [4 /*yield*/, getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, chooseApprover, false)];
|
|
807
|
+
case 9:
|
|
808
|
+
_b.approve = _c.sent();
|
|
809
|
+
_c.label = 10;
|
|
810
|
+
case 10: return [4 /*yield*/, handleProcessInstanceWorkitem(currentInstanceNode, 'approved', instanceHistoryId, userSession, comment, nextNodeOptions)];
|
|
811
|
+
case 11:
|
|
812
|
+
_c.sent();
|
|
813
|
+
return [2 /*return*/];
|
|
484
814
|
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
};
|
|
815
|
+
});
|
|
816
|
+
}); };
|
|
488
817
|
exports.processInstanceWorkitemApprove = processInstanceWorkitemApprove;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
818
|
+
var processInstanceWorkitemReject = function (instanceHistoryId, userSession, comment) { return __awaiter(void 0, void 0, void 0, function () {
|
|
819
|
+
var nextNodeOptions, instanceHistory, instanceId, currentInstanceNode, currentProcessNode, _a, _b;
|
|
820
|
+
return __generator(this, function (_c) {
|
|
821
|
+
switch (_c.label) {
|
|
822
|
+
case 0:
|
|
823
|
+
nextNodeOptions = null;
|
|
824
|
+
return [4 /*yield*/, getInstanceHistory(instanceHistoryId)];
|
|
825
|
+
case 1:
|
|
826
|
+
instanceHistory = _c.sent();
|
|
827
|
+
instanceId = instanceHistory.process_instance;
|
|
828
|
+
return [4 /*yield*/, getCurrentInstanceNode(instanceId)];
|
|
829
|
+
case 2:
|
|
830
|
+
currentInstanceNode = _c.sent();
|
|
831
|
+
return [4 /*yield*/, getProcessNode(instanceHistory.step_node)];
|
|
832
|
+
case 3:
|
|
833
|
+
currentProcessNode = _c.sent();
|
|
834
|
+
if (!(currentProcessNode.reject_behavior === 'back_to_previous')) return [3 /*break*/, 6];
|
|
835
|
+
nextNodeOptions = {};
|
|
836
|
+
_a = nextNodeOptions;
|
|
837
|
+
return [4 /*yield*/, getPreviousNode(instanceId, currentProcessNode, userSession)];
|
|
838
|
+
case 4:
|
|
839
|
+
_a.node = _c.sent();
|
|
840
|
+
_b = nextNodeOptions;
|
|
841
|
+
return [4 /*yield*/, getProcessNodeApprover(instanceId, nextNodeOptions.node, userSession, null, true)];
|
|
842
|
+
case 5:
|
|
843
|
+
_b.approve = _c.sent();
|
|
844
|
+
_c.label = 6;
|
|
845
|
+
case 6: return [4 /*yield*/, handleProcessInstanceWorkitem(currentInstanceNode, 'rejected', instanceHistoryId, userSession, comment, nextNodeOptions)];
|
|
846
|
+
case 7:
|
|
847
|
+
_c.sent();
|
|
848
|
+
return [2 /*return*/];
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}); };
|
|
502
852
|
exports.processInstanceWorkitemReject = processInstanceWorkitemReject;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
853
|
+
var processInstanceWorkitemReassign = function (instanceHistoryId, userSession, comment, chooseApprover) { return __awaiter(void 0, void 0, void 0, function () {
|
|
854
|
+
var history;
|
|
855
|
+
return __generator(this, function (_a) {
|
|
856
|
+
switch (_a.label) {
|
|
857
|
+
case 0:
|
|
858
|
+
if (_.isEmpty(chooseApprover)) {
|
|
859
|
+
throw new objectql_1.SteedosError('process_approval_error_reassign_approver_notFind');
|
|
860
|
+
}
|
|
861
|
+
if (!_.isString(chooseApprover)) {
|
|
862
|
+
throw new objectql_1.SteedosError('process_approval_error_reassign_approver_mustBeString');
|
|
863
|
+
}
|
|
864
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").update(instanceHistoryId, {
|
|
865
|
+
step_status: "reassigned",
|
|
866
|
+
actor: chooseApprover,
|
|
867
|
+
comments: comment
|
|
868
|
+
})];
|
|
869
|
+
case 1:
|
|
870
|
+
history = _a.sent();
|
|
871
|
+
return [4 /*yield*/, addInstanceHistory(userSession.spaceId, history.process_instance, 'pending', null, { nodeId: history.step_node, actor: chooseApprover, originalActor: history.original_actor, submitted_by: userSession.userId }, userSession)];
|
|
872
|
+
case 2:
|
|
873
|
+
_a.sent();
|
|
874
|
+
return [2 /*return*/];
|
|
875
|
+
}
|
|
514
876
|
});
|
|
515
|
-
|
|
516
|
-
};
|
|
877
|
+
}); };
|
|
517
878
|
exports.processInstanceWorkitemReassign = processInstanceWorkitemReassign;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
879
|
+
var processInstanceWorkitemRemovebyInstance = function (instanceId, userSession, comment) { return __awaiter(void 0, void 0, void 0, function () {
|
|
880
|
+
var processStatus;
|
|
881
|
+
return __generator(this, function (_a) {
|
|
882
|
+
switch (_a.label) {
|
|
883
|
+
case 0:
|
|
884
|
+
processStatus = 'removed';
|
|
885
|
+
return [4 /*yield*/, objectql.getObject("process_instance_history").updateMany([['process_instance', '=', instanceId], ['step_status', '=', 'pending']], { step_status: processStatus, comments: comment })];
|
|
886
|
+
case 1:
|
|
887
|
+
_a.sent();
|
|
888
|
+
return [4 /*yield*/, handleProcessInstanceNode(instanceId, null, processStatus, null, userSession)];
|
|
889
|
+
case 2:
|
|
890
|
+
_a.sent();
|
|
891
|
+
return [2 /*return*/];
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}); };
|
|
523
895
|
exports.processInstanceWorkitemRemovebyInstance = processInstanceWorkitemRemovebyInstance;
|
|
524
896
|
//# sourceMappingURL=process_manager.js.map
|