-
Notifications
You must be signed in to change notification settings - Fork 1
/
wunderlist-create-subtask.js
39 lines (34 loc) · 1.04 KB
/
wunderlist-create-subtask.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 WunderlistCreateSubtask(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 subtasks = wunderlistAPI.http.subtasks;
var params = {
'task_id': Number(n.taskId || msg.taskId),
'title': n.subtaskTitle || msg.payload
};
subtasks.create(params)
.done(function (taskData, statusCode) {
msg.subtask = 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-subtask', WunderlistCreateSubtask);
};