-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwunderlist-get-comments.js
56 lines (51 loc) · 1.5 KB
/
wunderlist-get-comments.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var wunderlistSDK = require('./wunderlist-sdk');
module.exports = function(RED) {
function WunderlistGetComments(n) {
RED.nodes.createNode(this, n);
var node = this;
this.config = RED.nodes.getNode(n.config);
this.on('input', function(msg, send, done) {
send = send || function() { node.send.apply(node,arguments) };
var wunderlistAPI = wunderlistSDK.getApi(node.config, msg);
var comments = wunderlistAPI.http.task_comments;
var listId = n.listId || msg.listId || false;
var taskId = n.taskId || msg.taskId || false;
if (taskId){
comments.forTask(taskId)
.done((taskCommentsData, statusCode) => {
msg.payload = taskCommentsData;
send(msg);
if (done) {
done();
}
})
.fail((resp, code) => {
var err = resp || 'Wunderlist API error';
if (done) {
done(err)
} else {
node.error(err);
}
});
} else if (listId){
comments.forList(listId)
.done((taskCommentsData, statusCode) => {
msg.payload = taskCommentsData;
send(msg);
if (done) {
done();
}
})
.fail((resp, code) => {
var err = resp || 'Wunderlist API error';
if (done) {
done(err)
} else {
node.error(err);
}
});
}
});
}
RED.nodes.registerType('wunderlist-get-comments', WunderlistGetComments);
};