@5minds/node-red-contrib-processcube 1.1.4-feature-19cce1-m0gp9iou → 1.1.4-feature-cf47e1-m0h7fe3x

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.
@@ -16,65 +16,34 @@ module.exports = function (RED) {
16
16
 
17
17
  let subscription;
18
18
 
19
+ function externalTaskCallback(event) {
20
+ return (externalTaskNotification) => {
21
+ if (config.externaltask != '' && config.externaltask != externalTaskNotification.flowNodeId) return;
22
+ node.send({
23
+ payload: {
24
+ flowNodeInstanceId: externalTaskNotification.flowNodeInstanceId,
25
+ externalTaskEvent: externalTaskNotification,
26
+ action: event,
27
+ type: 'externaltask',
28
+ },
29
+ });
30
+ };
31
+ }
32
+
19
33
  async function subscribe() {
20
34
  switch (config.eventtype) {
21
35
  case 'created':
22
- return await client.notification.onExternalTaskCreated(
23
- (externalTaskNotification) => {
24
- if (
25
- config.externaltask != '' &&
26
- config.externaltask != externalTaskNotification.flowNodeId
27
- )
28
- return;
29
- node.send({
30
- payload: {
31
- flowNodeInstanceId: externalTaskNotification.flowNodeInstanceId,
32
- externalTaskEvent: externalTaskNotification,
33
- action: 'created',
34
- type: 'externaltask',
35
- },
36
- });
37
- },
38
- { identity: currentIdentity }
39
- );
36
+ return await client.notification.onExternalTaskCreated(externalTaskCallback('created'), {
37
+ identity: currentIdentity,
38
+ });
40
39
  case 'locked':
41
- return await client.notification.onExternalTaskLocked(
42
- (externalTaskNotification) => {
43
- if (
44
- config.externaltask != '' &&
45
- config.externaltask != externalTaskNotification.flowNodeId
46
- )
47
- return;
48
- node.send({
49
- payload: {
50
- flowNodeInstanceId: externalTaskNotification.flowNodeInstanceId,
51
- externalTaskEvent: externalTaskNotification,
52
- action: 'locked',
53
- type: 'externaltask',
54
- },
55
- });
56
- },
57
- { identity: currentIdentity }
58
- );
40
+ return await client.notification.onExternalTaskLocked(externalTaskCallback('locked'), {
41
+ identity: currentIdentity,
42
+ });
59
43
  case 'unlocked':
60
- return await client.notification.onExternalTaskUnlocked(
61
- (externalTaskNotification) => {
62
- if (
63
- config.externaltask != '' &&
64
- config.externaltask != externalTaskNotification.flowNodeId
65
- )
66
- return;
67
- node.send({
68
- payload: {
69
- flowNodeInstanceId: externalTaskNotification.flowNodeInstanceId,
70
- externalTaskEvent: externalTaskNotification,
71
- action: 'unlocked',
72
- type: 'externaltask',
73
- },
74
- });
75
- },
76
- { identity: currentIdentity }
77
- );
44
+ return await client.notification.onExternalTaskUnlocked(externalTaskCallback('unlocked'), {
45
+ identity: currentIdentity,
46
+ });
78
47
  default:
79
48
  console.error('no such event: ' + config.eventtype);
80
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.1.4-feature-19cce1-m0gp9iou",
3
+ "version": "1.1.4-feature-cf47e1-m0h7fe3x",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -17,122 +17,51 @@ module.exports = function (RED) {
17
17
  let subscription;
18
18
  const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
19
19
 
20
+ function userTaskCallback(event) {
21
+ return async (userTaskNotification) => {
22
+ if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
23
+ const newQuery = {
24
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
25
+ ...query,
26
+ };
27
+
28
+ const matchingFlowNodes = await client.userTasks.query(newQuery, {
29
+ identity: currentIdentity,
30
+ });
31
+
32
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
33
+ const userTask = matchingFlowNodes.userTasks[0];
34
+
35
+ node.send({
36
+ payload: {
37
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
38
+ userTaskEvent: userTaskNotification,
39
+ userTask: userTask,
40
+ action: event,
41
+ type: 'usertask',
42
+ },
43
+ });
44
+ }
45
+ };
46
+ }
47
+
20
48
  async function subscribe() {
21
49
  switch (config.eventtype) {
22
50
  case 'new':
23
- return await client.userTasks.onUserTaskWaiting(
24
- async (userTaskNotification) => {
25
- if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
26
- const newQuery = {
27
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
28
- ...query,
29
- };
30
-
31
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
32
- identity: currentIdentity,
33
- });
34
-
35
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
36
- const userTask = matchingFlowNodes.userTasks[0];
37
-
38
- node.send({
39
- payload: {
40
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
41
- userTaskEvent: userTaskNotification,
42
- userTask: userTask,
43
- action: 'new',
44
- type: 'usertask',
45
- },
46
- });
47
- }
48
- },
49
- { identity: currentIdentity }
50
- );
51
+ return await client.userTasks.onUserTaskWaiting(userTaskCallback('new'), {
52
+ identity: currentIdentity,
53
+ });
51
54
  case 'finished':
52
- return await client.userTasks.onUserTaskFinished(
53
- async (userTaskNotification) => {
54
- if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
55
- const newQuery = {
56
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
57
- ...query,
58
- };
59
-
60
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
61
- identity: currentIdentity,
62
- });
63
-
64
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
65
- const userTask = matchingFlowNodes.userTasks[0];
66
-
67
- node.send({
68
- payload: {
69
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
70
- userTaskEvent: userTaskNotification,
71
- userTask: userTask,
72
- action: 'finished',
73
- type: 'usertask',
74
- },
75
- });
76
- }
77
- },
78
- { identity: currentIdentity }
79
- );
55
+ return await client.userTasks.onUserTaskFinished(userTaskCallback('finished'), {
56
+ identity: currentIdentity,
57
+ });
80
58
  case 'reserved':
81
- return await client.userTasks.onUserTaskReserved(
82
- async (userTaskNotification) => {
83
- if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
84
- const newQuery = {
85
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
86
- ...query,
87
- };
88
-
89
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
90
- identity: currentIdentity,
91
- });
92
-
93
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
94
- const userTask = matchingFlowNodes.userTasks[0];
95
-
96
- node.send({
97
- payload: {
98
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
99
- userTaskEvent: userTaskNotification,
100
- userTask: userTask,
101
- action: 'reserved',
102
- type: 'usertask',
103
- },
104
- });
105
- }
106
- },
107
- { identity: currentIdentity }
108
- );
59
+ return await client.userTasks.onUserTaskReserved(userTaskCallback('reserved'), {
60
+ identity: currentIdentity,
61
+ });
109
62
  case 'reservation-canceled':
110
63
  return await client.userTasks.onUserTaskReservationCanceled(
111
- async (userTaskNotification) => {
112
- if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
113
- const newQuery = {
114
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
115
- ...query,
116
- };
117
-
118
- const matchingFlowNodes = await client.userTasks.query(newQuery, {
119
- identity: currentIdentity,
120
- });
121
-
122
- if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
123
- const userTask = matchingFlowNodes.userTasks[0];
124
-
125
- node.send({
126
- payload: {
127
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
128
- userTaskEvent: userTaskNotification,
129
- userTask: userTask,
130
- action: 'reservation-canceled',
131
- type: 'usertask',
132
- },
133
- });
134
- }
135
- },
64
+ userTaskCallback('reservation-canceled'),
136
65
  { identity: currentIdentity }
137
66
  );
138
67
  default: