-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst-data-node.js
More file actions
79 lines (65 loc) · 2.96 KB
/
st-data-node.js
File metadata and controls
79 lines (65 loc) · 2.96 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module.exports = function (RED) {
function serviceTradeNode(config) {
RED.nodes.createNode(this, config);
const node = this;
node.authConfig = RED.nodes.getNode(config.authConfig);
node.on('input', async function (msg, send, done) {
if (!node.authConfig) {
node.error('Auth Config not set');
return done();
}
try {
const authToken = await node.authConfig.getAuthToken();
let requestUrl = msg.url || config.url;
const servicetradeobject = msg.servicetradeobject || config.servicetradeobject;
const limit = msg.limit || config.limit;
const page = typeof msg.page !== 'undefined' ? msg.page : config.page;
const jobstatus = msg.jobstatus || config.jobstatus; // coming from frontend
const updatedAfter = msg.updatedAfter || config.updatedAfter; // ADD THIS LINE
if (!requestUrl) {
node.error('URL not specified');
return done();
}
if (servicetradeobject) {
requestUrl += `/${servicetradeobject}`;
}
const params = new URLSearchParams();
if (limit) params.append('limit', limit);
if (page) params.append('page', page);
if (updatedAfter) params.append('updatedAfter', updatedAfter); // ADD THIS LINE
if (Array.isArray(jobstatus) && jobstatus.length > 0) {
params.append('status', jobstatus.join(','));
} else if (typeof jobstatus === 'string' && jobstatus.trim() !== '') {
params.append('status', jobstatus);
}
const queryString = params.toString();
if (queryString) {
requestUrl += `?${queryString}`;
}
const axios = require('axios');
let requestConfig = {
method: 'get',
maxBodyLength: Infinity,
url: requestUrl,
headers: {
'Cookie': `PHPSESSID=${authToken.data.authToken}`
}
};
const response = await axios.request(requestConfig);
msg.payload = response.data;
msg.limit = limit;
msg.page = page;
msg.servicetradeobject = servicetradeobject;
msg.jobstatus = jobstatus;
msg.updatedAfter = updatedAfter; // ADD THIS LINE
msg.url = requestUrl;
send(msg);
done();
} catch (error) {
node.error('Error making GET request: ' + error.message, msg);
done(error);
}
});
}
RED.nodes.registerType('get-st-data-node', serviceTradeNode);
};