-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusertask-input.js
40 lines (35 loc) · 1.59 KB
/
usertask-input.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module.exports = function (RED) {
function UserTaskInput(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg) {
node.engine = RED.nodes.getNode(config.engine);
const client = node.engine.engineClient;
if (!client) {
node.error('No engine configured.');
return;
}
let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
client.userTasks
.query(query)
.then((matchingFlowNodes) => {
if (config.sendtype === 'array') {
msg.payload = { userTasks: matchingFlowNodes.userTasks || [] };
node.send(msg);
} else if (config.sendtype === 'multi' && matchingFlowNodes?.userTasks?.length > 1) {
matchingFlowNodes.userTasks.forEach((userTask) => {
msg.payload = { userTask };
node.send(msg);
});
} else if (matchingFlowNodes?.userTasks?.length >= 1) {
msg.payload = { userTask: matchingFlowNodes.userTasks[0] };
node.send(msg);
} else node.log(`No user tasks found for query: ${JSON.stringify(query)}`);
})
.catch((error) => {
node.error(JSON.stringify(error));
});
});
}
RED.nodes.registerType('usertask-input', UserTaskInput);
};