-
Notifications
You must be signed in to change notification settings - Fork 1
/
wunderlist-create-comment.js
39 lines (34 loc) · 1.02 KB
/
wunderlist-create-comment.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
var wunderlistSDK = require('./wunderlist-sdk');
module.exports = function(RED) {
function WunderlistComment(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 params = {
'task_id': Number(n.taskId || msg.taskId),
'text': n.comment || msg.payload
};
comments.create(params)
.done(function (taskData, statusCode) {
msg.comment = taskData;
send(msg);
if (done) {
done();
}
})
.fail(function (resp, code) {
var err = resp || 'Wunderlist API error';
if (done) {
done(err)
} else {
node.error(err);
}
});
});
}
RED.nodes.registerType('wunderlist-create-comment', WunderlistComment);
};