forked from jeffdonthemic/node-red-contrib-salesforce
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsoql.js
42 lines (37 loc) · 1.1 KB
/
soql.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
41
42
const actionHelper = require('./lib/action_helper');
/**
* Executes a SOQL query based on configuration and msg
*
* @param {node-red-node} node the current node
* @param {msg} msg the incoming message
*/
const handleInput = (node, msg) => {
const config = node.config;
const realAction = (org, payload) => {
return new Promise((resolve, reject) => {
Object.assign(payload, {
fetchAll: config.fetchAll,
query: msg.query || config.query
});
org
.query(payload)
.then((results) => {
const finalResults = results.records.map((r) => r.toJSON());
resolve(finalResults);
})
.catch((err) => reject(err));
});
};
actionHelper.inputToSFAction(node, msg, realAction);
};
/* Make code available */
module.exports = function(RED) {
function SoqlQuery(config) {
const node = this;
RED.nodes.createNode(node, config);
node.connection = RED.nodes.getNode(config.connection);
node.config = config;
node.on('input', (msg) => handleInput(node, msg));
}
RED.nodes.registerType('soql', SoqlQuery);
};