@5minds/node-red-contrib-processcube 1.1.4-feature-cf47e1-m0h7fe3x → 1.1.4-feature-bc1698-m0kn1ci4

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,14 +16,14 @@ module.exports = function (RED) {
16
16
 
17
17
  let subscription;
18
18
 
19
- function externalTaskCallback(event) {
19
+ function externalTaskCallback() {
20
20
  return (externalTaskNotification) => {
21
21
  if (config.externaltask != '' && config.externaltask != externalTaskNotification.flowNodeId) return;
22
22
  node.send({
23
23
  payload: {
24
24
  flowNodeInstanceId: externalTaskNotification.flowNodeInstanceId,
25
25
  externalTaskEvent: externalTaskNotification,
26
- action: event,
26
+ action: config.eventtype,
27
27
  type: 'externaltask',
28
28
  },
29
29
  });
@@ -31,21 +31,27 @@ module.exports = function (RED) {
31
31
  }
32
32
 
33
33
  async function subscribe() {
34
- switch (config.eventtype) {
35
- case 'created':
36
- return await client.notification.onExternalTaskCreated(externalTaskCallback('created'), {
34
+ const eventHandlers = {
35
+ created: () =>
36
+ client.notification.onExternalTaskCreated(externalTaskCallback('created'), {
37
37
  identity: currentIdentity,
38
- });
39
- case 'locked':
40
- return await client.notification.onExternalTaskLocked(externalTaskCallback('locked'), {
38
+ }),
39
+ locked: () =>
40
+ client.notification.onExternalTaskLocked(externalTaskCallback('locked'), {
41
41
  identity: currentIdentity,
42
- });
43
- case 'unlocked':
44
- return await client.notification.onExternalTaskUnlocked(externalTaskCallback('unlocked'), {
42
+ }),
43
+ unlocked: () =>
44
+ client.notification.onExternalTaskUnlocked(externalTaskCallback('unlocked'), {
45
45
  identity: currentIdentity,
46
- });
47
- default:
48
- console.error('no such event: ' + config.eventtype);
46
+ }),
47
+ };
48
+
49
+ const handler = eventHandlers[config.eventtype];
50
+
51
+ if (handler) {
52
+ return await handler();
53
+ } else {
54
+ console.error('No such event: ' + config.eventtype);
49
55
  }
50
56
  }
51
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.1.4-feature-cf47e1-m0h7fe3x",
3
+ "version": "1.1.4-feature-bc1698-m0kn1ci4",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -17,7 +17,7 @@ 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) {
20
+ function userTaskCallback() {
21
21
  return async (userTaskNotification) => {
22
22
  if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
23
23
  const newQuery = {
@@ -37,7 +37,7 @@ module.exports = function (RED) {
37
37
  flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
38
38
  userTaskEvent: userTaskNotification,
39
39
  userTask: userTask,
40
- action: event,
40
+ action: config.eventtype,
41
41
  type: 'usertask',
42
42
  },
43
43
  });
@@ -46,26 +46,23 @@ module.exports = function (RED) {
46
46
  }
47
47
 
48
48
  async function subscribe() {
49
- switch (config.eventtype) {
50
- case 'new':
51
- return await client.userTasks.onUserTaskWaiting(userTaskCallback('new'), {
49
+ const eventHandlers = {
50
+ new: () => client.userTasks.onUserTaskWaiting(userTaskCallback(), { identity: currentIdentity }),
51
+ finished: () =>
52
+ client.userTasks.onUserTaskFinished(userTaskCallback(), { identity: currentIdentity }),
53
+ reserved: () =>
54
+ client.userTasks.onUserTaskReserved(userTaskCallback(), { identity: currentIdentity }),
55
+ 'reservation-canceled': () =>
56
+ client.userTasks.onUserTaskReservationCanceled(userTaskCallback(), {
52
57
  identity: currentIdentity,
53
- });
54
- case 'finished':
55
- return await client.userTasks.onUserTaskFinished(userTaskCallback('finished'), {
56
- identity: currentIdentity,
57
- });
58
- case 'reserved':
59
- return await client.userTasks.onUserTaskReserved(userTaskCallback('reserved'), {
60
- identity: currentIdentity,
61
- });
62
- case 'reservation-canceled':
63
- return await client.userTasks.onUserTaskReservationCanceled(
64
- userTaskCallback('reservation-canceled'),
65
- { identity: currentIdentity }
66
- );
67
- default:
68
- console.error('no such event: ' + config.eventtype);
58
+ }),
59
+ };
60
+
61
+ const handler = eventHandlers[config.eventtype];
62
+ if (handler) {
63
+ return await handler();
64
+ } else {
65
+ console.error('no such event: ' + config.eventtype);
69
66
  }
70
67
  }
71
68