This repository was archived by the owner on Jan 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessdefinition-query.js
More file actions
49 lines (40 loc) · 1.8 KB
/
processdefinition-query.js
File metadata and controls
49 lines (40 loc) · 1.8 KB
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
41
42
43
44
45
46
47
48
49
module.exports = function (RED) {
function ProcessdefinitionQuery(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.', msg);
return;
}
let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
if (typeof query !== 'object' || Array.isArray(query) || query === null) {
query = {};
}
node.log(`Querying process definitions with query: ${JSON.stringify(query)}`);
const isUser = !!msg._client?.user && !!msg._client.user.accessToken;
const identity = isUser ? { userId: msg._client.user.id, token: msg._client.user.accessToken } : null;
query.identity = identity;
client.processDefinitions
.getAll(query)
.then((matchingProcessDefinitions) => {
if (config.models_only) {
const models = matchingProcessDefinitions.processDefinitions.flatMap(processDefinition => processDefinition.processModels);
msg.payload = {
models: models,
totalCount: models.length,
};
} else {
msg.payload = matchingProcessDefinitions;
}
node.send(msg);
})
.catch((error) => {
node.error(error, msg);
});
});
}
RED.nodes.registerType('processdefinition-query', ProcessdefinitionQuery);
};