@beauraines/rtm-api 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +285 -0
- package/config.js +22 -0
- package/docs/RTMClient.html +2798 -0
- package/docs/RTMError.html +1029 -0
- package/docs/RTMList.html +966 -0
- package/docs/RTMResponse.html +868 -0
- package/docs/RTMSuccess.html +337 -0
- package/docs/RTMTask.html +2461 -0
- package/docs/RTMUser.html +6761 -0
- package/docs/client_auth.js.html +123 -0
- package/docs/client_index.js.html +241 -0
- package/docs/client_user.js.html +170 -0
- package/docs/global.html +386 -0
- package/docs/index.html +305 -0
- package/docs/list_index.js.html +159 -0
- package/docs/response_error.js.html +172 -0
- package/docs/response_response.js.html +160 -0
- package/docs/response_success.js.html +104 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/styles/jsdoc.css +664 -0
- package/docs/styles/prettify.css +79 -0
- package/docs/task_helper.js.html +531 -0
- package/docs/task_index.js.html +304 -0
- package/docs/user_index.js.html +347 -0
- package/docs/user_lists.js.html +208 -0
- package/docs/user_tasks.js.html +703 -0
- package/jsdoc.json +13 -0
- package/package.json +33 -0
- package/src/client/auth.js +65 -0
- package/src/client/index.js +182 -0
- package/src/client/user.js +112 -0
- package/src/list/helper.js +131 -0
- package/src/list/index.js +101 -0
- package/src/response/error.js +114 -0
- package/src/response/index.js +8 -0
- package/src/response/parse.js +51 -0
- package/src/response/response.js +102 -0
- package/src/response/success.js +46 -0
- package/src/task/helper.js +469 -0
- package/src/task/index.js +264 -0
- package/src/user/index.js +288 -0
- package/src/user/lists.js +150 -0
- package/src/user/tasks.js +708 -0
- package/src/utils/auth.js +188 -0
- package/src/utils/fetch.js +67 -0
- package/src/utils/get.js +247 -0
- package/src/utils/sign.js +93 -0
- package/src/utils/taskIds.js +188 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const RTMTask = require('./index.js');
|
|
4
|
+
const taskIds = require('../utils/taskIds.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* API Call: rtm.tasks.getList
|
|
8
|
+
* @param user RTMUser
|
|
9
|
+
* @param [filter] Task Filter
|
|
10
|
+
* @param callback Callback function(err, tasks)
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
function get(user, filter, callback) {
|
|
14
|
+
let params = {};
|
|
15
|
+
if ( callback === undefined && typeof filter === 'function' ) {
|
|
16
|
+
callback = filter;
|
|
17
|
+
}
|
|
18
|
+
else if ( filter !== '' ) {
|
|
19
|
+
params.filter = filter;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
user.get('rtm.tasks.getList', params, function(err, resp) {
|
|
23
|
+
if ( err ) {
|
|
24
|
+
return callback(err);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// List of task to return
|
|
28
|
+
let rtn = [];
|
|
29
|
+
|
|
30
|
+
// Parse each List
|
|
31
|
+
let lists = resp.tasks.list;
|
|
32
|
+
if ( lists !== undefined ) {
|
|
33
|
+
for ( let i = 0; i < lists.length; i++ ) {
|
|
34
|
+
let list = lists[i];
|
|
35
|
+
|
|
36
|
+
// Parse the List's TaskSeries
|
|
37
|
+
if ( list.taskseries ) {
|
|
38
|
+
if ( !Array.isArray(list.taskseries) ) {
|
|
39
|
+
list.taskseries = [list.taskseries];
|
|
40
|
+
}
|
|
41
|
+
for ( let j = 0; j < list.taskseries.length; j++ ) {
|
|
42
|
+
let series = list.taskseries[j];
|
|
43
|
+
|
|
44
|
+
// Parse the TaskSeries' Tasks
|
|
45
|
+
if ( !Array.isArray(series.task) ) {
|
|
46
|
+
series.task = [series.task];
|
|
47
|
+
}
|
|
48
|
+
for ( let k = 0; k < series.task.length; k++ ) {
|
|
49
|
+
let task = series.task[k];
|
|
50
|
+
rtn.push(new RTMTask(user.id, list.id, series, task));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Save the task indices
|
|
58
|
+
taskIds.save();
|
|
59
|
+
|
|
60
|
+
// Return with the callback
|
|
61
|
+
return callback(null, rtn);
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* API Call rtm.tasks.add
|
|
68
|
+
* Note: this uses RTM's 'smart add'
|
|
69
|
+
* @param {string} name Task Name (or smart add syntax)
|
|
70
|
+
* @param {{due: *, priority: *, list: *, tags: *, location: *, start: *, repeat: *, estimate: *, to: *, url: *, note: *}} props Additional task properties
|
|
71
|
+
* @param user RTM User
|
|
72
|
+
* @param callback Callback function(err)
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
function add(name, props, user, callback) {
|
|
76
|
+
|
|
77
|
+
// Parse the props keys
|
|
78
|
+
if ( props.due ) {
|
|
79
|
+
name = name + " ^" + props.due;
|
|
80
|
+
}
|
|
81
|
+
if ( props.priority ) {
|
|
82
|
+
name = name + " !" + props.priority
|
|
83
|
+
}
|
|
84
|
+
if ( props.list ) {
|
|
85
|
+
name = name + " #" + props.list;
|
|
86
|
+
}
|
|
87
|
+
if ( props.tags ) {
|
|
88
|
+
if ( !Array.isArray(props.tags) ) {
|
|
89
|
+
props.tags = [props.tags];
|
|
90
|
+
}
|
|
91
|
+
for ( let i = 0; i < props.tags.length; i++ ) {
|
|
92
|
+
name = name + " #" + props.tags[i];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if ( props.location ) {
|
|
96
|
+
name = name + " @" + props.location;
|
|
97
|
+
}
|
|
98
|
+
if ( props.start ) {
|
|
99
|
+
name = name + " ~" + props.start;
|
|
100
|
+
}
|
|
101
|
+
if ( props.repeat ) {
|
|
102
|
+
name = name + " *" + props.repeat;
|
|
103
|
+
}
|
|
104
|
+
if ( props.estimate ) {
|
|
105
|
+
name = name + " =" + props.estimate;
|
|
106
|
+
}
|
|
107
|
+
if ( props.to ) {
|
|
108
|
+
name = name + " +" + props.to;
|
|
109
|
+
}
|
|
110
|
+
if ( props.url ) {
|
|
111
|
+
name = name + " " + props.url;
|
|
112
|
+
}
|
|
113
|
+
if ( props.note ) {
|
|
114
|
+
name = name + " //" + props.note;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Set the request params
|
|
118
|
+
let params = {
|
|
119
|
+
timeline: user.timeline,
|
|
120
|
+
name: name,
|
|
121
|
+
parse: '1'
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Make the API Request
|
|
125
|
+
user.get('rtm.tasks.add', params, function(err) {
|
|
126
|
+
return callback(err);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* API Call: rtm.tasks.complete
|
|
133
|
+
* @param {number} listId RTM List ID
|
|
134
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
135
|
+
* @param {number} taskId RTM Task ID
|
|
136
|
+
* @param {RTMUser} user RTM User
|
|
137
|
+
* @param {function} callback function(err)
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
function complete(listId, taskSeriesId, taskId, user, callback) {
|
|
141
|
+
let params = {
|
|
142
|
+
timeline: user.timeline,
|
|
143
|
+
list_id: listId,
|
|
144
|
+
taskseries_id: taskSeriesId,
|
|
145
|
+
task_id: taskId
|
|
146
|
+
};
|
|
147
|
+
user.get('rtm.tasks.complete', params, function(err) {
|
|
148
|
+
return callback(err);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* API Call: rtm.tasks.uncomplete
|
|
154
|
+
* @param {number} listId RTM List ID
|
|
155
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
156
|
+
* @param {number} taskId RTM Task ID
|
|
157
|
+
* @param {RTMUser} user RTM User
|
|
158
|
+
* @param {function} callback function(err)
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
function uncomplete(listId, taskSeriesId, taskId, user, callback) {
|
|
162
|
+
let params = {
|
|
163
|
+
timeline: user.timeline,
|
|
164
|
+
list_id: listId,
|
|
165
|
+
taskseries_id: taskSeriesId,
|
|
166
|
+
task_id: taskId
|
|
167
|
+
};
|
|
168
|
+
user.get('rtm.tasks.uncomplete', params, function(err) {
|
|
169
|
+
return callback(err);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* API Call: rtm.tasks.setPriority
|
|
175
|
+
* @param {number} listId RTM List ID
|
|
176
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
177
|
+
* @param {number} taskId RTM Task ID
|
|
178
|
+
* @param {int} priority Task Priority
|
|
179
|
+
* @param {RTMUser} user RTM User
|
|
180
|
+
* @param {function} callback function(err)
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
function priority(listId, taskSeriesId, taskId, priority, user, callback) {
|
|
184
|
+
let params = {
|
|
185
|
+
timeline: user.timeline,
|
|
186
|
+
list_id: listId,
|
|
187
|
+
taskseries_id: taskSeriesId,
|
|
188
|
+
task_id: taskId,
|
|
189
|
+
priority: priority
|
|
190
|
+
};
|
|
191
|
+
user.get('rtm.tasks.setPriority', params, function(err) {
|
|
192
|
+
return callback(err);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* API Call: rtm.tasks.addTags
|
|
198
|
+
* @param {number} listId RTM List ID
|
|
199
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
200
|
+
* @param {number} taskId RTM Task ID
|
|
201
|
+
* @param {string[]} tags Tags to Add
|
|
202
|
+
* @param {RTMUser} user RTM User
|
|
203
|
+
* @param {function} callback function(err)
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
function addTags(listId, taskSeriesId, taskId, tags, user, callback) {
|
|
207
|
+
let params = {
|
|
208
|
+
timeline: user.timeline,
|
|
209
|
+
list_id: listId,
|
|
210
|
+
taskseries_id: taskSeriesId,
|
|
211
|
+
task_id: taskId,
|
|
212
|
+
tags: tags.join(',')
|
|
213
|
+
};
|
|
214
|
+
user.get('rtm.tasks.addTags', params, function(err) {
|
|
215
|
+
return callback(err);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* API Call: rtm.tasks.notes.add
|
|
221
|
+
* @param {number} listId RTM List ID
|
|
222
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
223
|
+
* @param {number} taskId RTM Task ID
|
|
224
|
+
* @param {string} title Title of Note
|
|
225
|
+
* @param {string|string[]} notes Note(s) to add to the Task
|
|
226
|
+
* @param {RTMUser} user RTM User
|
|
227
|
+
* @param {function} callback function(err)
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
function addNotes(listId, taskSeriesId, taskId, title, notes, user, callback) {
|
|
231
|
+
let params = {
|
|
232
|
+
timeline: user.timeline,
|
|
233
|
+
list_id: listId,
|
|
234
|
+
taskseries_id: taskSeriesId,
|
|
235
|
+
task_id: taskId,
|
|
236
|
+
note_title: title,
|
|
237
|
+
note_text: notes
|
|
238
|
+
};
|
|
239
|
+
user.get('rtm.tasks.notes.add', params, function(err) {
|
|
240
|
+
return callback(err);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* API Call: rtm.tasks.delete
|
|
246
|
+
* @param {number} listId RTM List ID
|
|
247
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
248
|
+
* @param {number} taskId RTM Task ID
|
|
249
|
+
* @param {RTMUser} user RTM User
|
|
250
|
+
* @param {function} callback function(err)
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
function remove(listId, taskSeriesId, taskId, user, callback) {
|
|
254
|
+
let params = {
|
|
255
|
+
timeline: user.timeline,
|
|
256
|
+
list_id: listId,
|
|
257
|
+
taskseries_id: taskSeriesId,
|
|
258
|
+
task_id: taskId,
|
|
259
|
+
};
|
|
260
|
+
user.get('rtm.tasks.delete', params, function(err) {
|
|
261
|
+
return callback(err);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* API Call: rtm.tasks.movePriority
|
|
267
|
+
* @param {number} listId RTM List ID
|
|
268
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
269
|
+
* @param {number} taskId RTM Task ID
|
|
270
|
+
* @param {string} direction Direction to move 'up' or 'down'
|
|
271
|
+
* @param {RTMUser} user RTM User
|
|
272
|
+
* @param {function} callback function(err)
|
|
273
|
+
* @private
|
|
274
|
+
*/
|
|
275
|
+
function movePriority(listId, taskSeriesId, taskId, direction, user, callback) {
|
|
276
|
+
if ( direction.toLowerCase() !== 'up' && direction.toLowerCase() !== 'down' ) {
|
|
277
|
+
throw "Incorrect priority direction. Must be either 'up' or 'down'";
|
|
278
|
+
}
|
|
279
|
+
let params = {
|
|
280
|
+
timeline: user.timeline,
|
|
281
|
+
list_id: listId,
|
|
282
|
+
taskseries_id: taskSeriesId,
|
|
283
|
+
task_id: taskId,
|
|
284
|
+
direction: direction.toLowerCase()
|
|
285
|
+
};
|
|
286
|
+
user.get('rtm.tasks.movePriority', params, function(err) {
|
|
287
|
+
return callback(err);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* API Call: rtm.tasks.moveTo
|
|
293
|
+
* @param {number} listId RTM List ID (original)
|
|
294
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
295
|
+
* @param {number} taskId RTM Task ID
|
|
296
|
+
* @param {number} toListId RTM List ID (new)
|
|
297
|
+
* @param {RTMUser} user RTM User
|
|
298
|
+
* @param {function} callback function(err)
|
|
299
|
+
* @private
|
|
300
|
+
*/
|
|
301
|
+
function move(listId, taskSeriesId, taskId, toListId, user, callback) {
|
|
302
|
+
let params = {
|
|
303
|
+
timeline: user.timeline,
|
|
304
|
+
from_list_id: listId,
|
|
305
|
+
taskseries_id: taskSeriesId,
|
|
306
|
+
task_id: taskId,
|
|
307
|
+
to_list_id: toListId
|
|
308
|
+
};
|
|
309
|
+
user.get('rtm.tasks.moveTo', params, function(err) {
|
|
310
|
+
return callback(err);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* API Call: rtm.tasks.postpone
|
|
316
|
+
* @param {number} listId RTM List ID
|
|
317
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
318
|
+
* @param {number} taskId RTM Task ID
|
|
319
|
+
* @param {RTMUser} user RTM User
|
|
320
|
+
* @param {function} callback function(err)
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
function postpone(listId, taskSeriesId, taskId, user, callback) {
|
|
324
|
+
let params = {
|
|
325
|
+
timeline: user.timeline,
|
|
326
|
+
list_id: listId,
|
|
327
|
+
taskseries_id: taskSeriesId,
|
|
328
|
+
task_id: taskId
|
|
329
|
+
};
|
|
330
|
+
user.get('rtm.tasks.postpone', params, function(err) {
|
|
331
|
+
return callback(err);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* API Call: rtm.tasks.removeTags
|
|
337
|
+
* @param {number} listId RTM List ID
|
|
338
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
339
|
+
* @param {number} taskId RTM Task ID
|
|
340
|
+
* @param {string[]} tags Tags to Remove
|
|
341
|
+
* @param {RTMUser} user RTM User
|
|
342
|
+
* @param {function} callback function(err)
|
|
343
|
+
* @private
|
|
344
|
+
*/
|
|
345
|
+
function removeTags(listId, taskSeriesId, taskId, tags, user, callback) {
|
|
346
|
+
let params = {
|
|
347
|
+
timeline: user.timeline,
|
|
348
|
+
list_id: listId,
|
|
349
|
+
taskseries_id: taskSeriesId,
|
|
350
|
+
task_id: taskId,
|
|
351
|
+
tags: tags.join(',')
|
|
352
|
+
};
|
|
353
|
+
user.get('rtm.tasks.removeTags', params, function(err) {
|
|
354
|
+
return callback(err);
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* API Call: rtm.tasks.setDueDate
|
|
360
|
+
* @param {number} listId RTM List ID
|
|
361
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
362
|
+
* @param {number} taskId RTM Task ID
|
|
363
|
+
* @param {string} due Task Due Date (will be parsed by RTM)
|
|
364
|
+
* @param {RTMUser} user RTM User
|
|
365
|
+
* @param {function} callback function(err)
|
|
366
|
+
* @private
|
|
367
|
+
*/
|
|
368
|
+
function setDueDate(listId, taskSeriesId, taskId, due, user, callback) {
|
|
369
|
+
let params = {
|
|
370
|
+
timeline: user.timeline,
|
|
371
|
+
list_id: listId,
|
|
372
|
+
taskseries_id: taskSeriesId,
|
|
373
|
+
task_id: taskId,
|
|
374
|
+
due: due,
|
|
375
|
+
parse: 1
|
|
376
|
+
};
|
|
377
|
+
user.get('rtm.tasks.setDueDate', params, function(err) {
|
|
378
|
+
return callback(err);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* API Call: rtm.tasks.setStartDate
|
|
384
|
+
* @param {number} listId RTM List ID
|
|
385
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
386
|
+
* @param {number} taskId RTM Task ID
|
|
387
|
+
* @param {string} start Task Start Date/Time (will be parsed by RTM)
|
|
388
|
+
* @param {RTMUser} user RTM User
|
|
389
|
+
* @param {Function} callback Callback function(err)
|
|
390
|
+
*/
|
|
391
|
+
function setStartDate(listId, taskSeriesId, taskId, start, user, callback) {
|
|
392
|
+
let params = {
|
|
393
|
+
timeline: user.timeline,
|
|
394
|
+
list_id: listId,
|
|
395
|
+
taskseries_id: taskSeriesId,
|
|
396
|
+
task_id: taskId,
|
|
397
|
+
start: start,
|
|
398
|
+
parse: 1
|
|
399
|
+
};
|
|
400
|
+
user.get('rtm.tasks.setStartDate', params, function(err) {
|
|
401
|
+
return callback(err);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* API Call: rtm.tasks.setName
|
|
407
|
+
* @param {number} listId RTM List ID
|
|
408
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
409
|
+
* @param {number} taskId RTM Task ID
|
|
410
|
+
* @param {string} name New Task Name
|
|
411
|
+
* @param {RTMUser} user RTM User
|
|
412
|
+
* @param {function} callback function(err)
|
|
413
|
+
* @private
|
|
414
|
+
*/
|
|
415
|
+
function setName(listId, taskSeriesId, taskId, name, user, callback) {
|
|
416
|
+
let params = {
|
|
417
|
+
timeline: user.timeline,
|
|
418
|
+
list_id: listId,
|
|
419
|
+
taskseries_id: taskSeriesId,
|
|
420
|
+
task_id: taskId,
|
|
421
|
+
name: name
|
|
422
|
+
};
|
|
423
|
+
user.get('rtm.tasks.setName', params, function(err) {
|
|
424
|
+
return callback(err);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* API Call: rtm.tasks.setURL
|
|
430
|
+
* @param {number} listId RTM List ID
|
|
431
|
+
* @param {number} taskSeriesId RTM Task Series ID
|
|
432
|
+
* @param {number} taskId RTM Task ID
|
|
433
|
+
* @param {string} url New Task URL
|
|
434
|
+
* @param {RTMUser} user RTM User
|
|
435
|
+
* @param {function} callback function(err)
|
|
436
|
+
* @private
|
|
437
|
+
*/
|
|
438
|
+
function setURL(listId, taskSeriesId, taskId, url, user, callback) {
|
|
439
|
+
let params = {
|
|
440
|
+
timeline: user.timeline,
|
|
441
|
+
list_id: listId,
|
|
442
|
+
taskseries_id: taskSeriesId,
|
|
443
|
+
task_id: taskId,
|
|
444
|
+
url: url
|
|
445
|
+
};
|
|
446
|
+
user.get('rtm.tasks.setURL', params, function(err) {
|
|
447
|
+
return callback(err);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
module.exports = {
|
|
453
|
+
get: get,
|
|
454
|
+
add: add,
|
|
455
|
+
complete: complete,
|
|
456
|
+
uncomplete: uncomplete,
|
|
457
|
+
priority: priority,
|
|
458
|
+
addNotes: addNotes,
|
|
459
|
+
addTags: addTags,
|
|
460
|
+
remove: remove,
|
|
461
|
+
movePriority: movePriority,
|
|
462
|
+
move: move,
|
|
463
|
+
postpone: postpone,
|
|
464
|
+
removeTags: removeTags,
|
|
465
|
+
setDueDate: setDueDate,
|
|
466
|
+
setStartDate: setStartDate,
|
|
467
|
+
setName: setName,
|
|
468
|
+
setURL: setURL
|
|
469
|
+
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const taskIds = require('../utils/taskIds.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ### RTM List
|
|
8
|
+
*
|
|
9
|
+
* This Class is used to represent the combined properties of an RTM TaskSeries
|
|
10
|
+
* combined with an RTM Task. If an RTM TaskSeries has more than one task
|
|
11
|
+
* property then there will be multiple `RTMTask` instances representing the
|
|
12
|
+
* data (which will duplicate the TaskSeries properties).
|
|
13
|
+
*
|
|
14
|
+
* Each instance of an `RTMTask` contains a `list_id`, `taskseries_id` and
|
|
15
|
+
* `task_id` property.
|
|
16
|
+
*
|
|
17
|
+
* All of the taskseries and task properties from the RTM API are directly
|
|
18
|
+
* accessible as `RTMTask` properties.
|
|
19
|
+
*
|
|
20
|
+
* ```
|
|
21
|
+
* let task = new RTMTask(..., ..., ...);
|
|
22
|
+
* let name = task.name;
|
|
23
|
+
* let priority = task.priority;
|
|
24
|
+
* ```
|
|
25
|
+
* @class
|
|
26
|
+
*/
|
|
27
|
+
class RTMTask {
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a new RTM Task
|
|
31
|
+
* @param {number} userId RTM User ID
|
|
32
|
+
* @param {number} listId RTM List ID
|
|
33
|
+
* @param {object} series Taskseries properties (resp.task.list[].taskseries[])
|
|
34
|
+
* @param {object} task Task properties (resp.task.list[].taskseries[].task)
|
|
35
|
+
*/
|
|
36
|
+
constructor(userId, listId, series, task) {
|
|
37
|
+
|
|
38
|
+
// List added after construction
|
|
39
|
+
this._list = undefined;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* List ID
|
|
43
|
+
* @type {Number}
|
|
44
|
+
*/
|
|
45
|
+
this.list_id = parseFloat(listId);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* TaskSeries ID
|
|
49
|
+
* @type {Number}
|
|
50
|
+
*/
|
|
51
|
+
this.taskseries_id = parseFloat(series.id);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Task Creation Date
|
|
55
|
+
* @type {Date|undefined}
|
|
56
|
+
*/
|
|
57
|
+
this.created = series.created?.toString() === '' ? undefined : new Date(series.created);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Task Modification Date
|
|
61
|
+
* @type {Date|undefined}
|
|
62
|
+
*/
|
|
63
|
+
this.modified = series.modified?.toString() === '' ? undefined : new Date(series.modified);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Task Name
|
|
67
|
+
* @type {string}
|
|
68
|
+
*/
|
|
69
|
+
this.name = series.name;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Task Creation Source
|
|
73
|
+
* @type {string}
|
|
74
|
+
*/
|
|
75
|
+
this.source = series.source;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Task Reference URL
|
|
79
|
+
* @type {string|undefined}
|
|
80
|
+
*/
|
|
81
|
+
this.url = series.url === '' ? undefined : series.url;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Task Location ID
|
|
85
|
+
* @type {number|undefined}
|
|
86
|
+
*/
|
|
87
|
+
this.location_id = series.location_id?.toString() === '' ? undefined : parseFloat(series.location_id);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Task Tags
|
|
91
|
+
* @type {string[]}
|
|
92
|
+
*/
|
|
93
|
+
this.tags = series.tags.tag !== undefined ? series.tags.tag : [];
|
|
94
|
+
if ( !Array.isArray(this.tags) ) {
|
|
95
|
+
this.tags = [this.tags];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Task Participants
|
|
100
|
+
* @type {Array}
|
|
101
|
+
*/
|
|
102
|
+
this.participants = series.participants;
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Task Note
|
|
107
|
+
* @typedef {Object} RTMTask~Note
|
|
108
|
+
* @property {number} id Note ID
|
|
109
|
+
* @property {Date} created Note Creation Date
|
|
110
|
+
* @property {Date} modified Note Modified Date
|
|
111
|
+
* @property {string} title Note Title
|
|
112
|
+
* @property {string} body Note Body
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Task Notes
|
|
117
|
+
* @type {RTMTask~Note[]}
|
|
118
|
+
*/
|
|
119
|
+
this.notes = series.notes.note !== undefined ? series.notes.note : [];
|
|
120
|
+
if ( !Array.isArray(this.notes) ) {
|
|
121
|
+
this.notes = [this.notes];
|
|
122
|
+
}
|
|
123
|
+
for ( let i = 0; i < this.notes.length; i++ ) {
|
|
124
|
+
this.notes[i].id = parseFloat(this.notes[i].id);
|
|
125
|
+
this.notes[i].created = new Date(this.notes[i].created);
|
|
126
|
+
this.notes[i].modified = new Date(this.notes[i].modified);
|
|
127
|
+
this.notes[i].title = this.notes[i].title === '' ? undefined : this.notes[i].title;
|
|
128
|
+
this.notes[i].body = this.notes[i]['$t'];
|
|
129
|
+
delete this.notes[i]['$t'];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Task ID
|
|
134
|
+
* @type {Number}
|
|
135
|
+
*/
|
|
136
|
+
this.task_id = parseFloat(task.id);
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Task Due Date
|
|
140
|
+
* @type {Date|undefined}
|
|
141
|
+
*/
|
|
142
|
+
this.due = task.due?.toString() === '' ? undefined : new Date(task.due);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Task Due Time Flag (true when `due` includes a Due Time)
|
|
146
|
+
* @type {boolean}
|
|
147
|
+
*/
|
|
148
|
+
this.has_due_time = task.has_due_time?.toString() === '1';
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Task Start Date
|
|
152
|
+
* @type {Date|undefined}
|
|
153
|
+
*/
|
|
154
|
+
this.start = task.start?.toString() === '' ? undefined : new Date(task.start);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Task Start Time Flag (true when `start` includes a Start Time)
|
|
158
|
+
* @type {boolean}
|
|
159
|
+
*/
|
|
160
|
+
this.has_start_time = task.has_start_time?.toString() === '1';
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Task Added Date
|
|
164
|
+
* @type {Date|undefined}
|
|
165
|
+
*/
|
|
166
|
+
this.added = task.added?.toString() === '' ? undefined : new Date(task.added);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Task Completed Date
|
|
170
|
+
* @type {Date|undefined}
|
|
171
|
+
*/
|
|
172
|
+
this.completed = task.completed?.toString() === '' ? undefined : new Date(task.completed);
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Task Completed Flag (true when task is marked as completed)
|
|
176
|
+
* @type {boolean}
|
|
177
|
+
*/
|
|
178
|
+
this.isCompleted = this.completed !== undefined;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Task Deleted Flag
|
|
182
|
+
* @type {Date|undefined}
|
|
183
|
+
*/
|
|
184
|
+
this.deleted = task.deleted?.toString() === '' ? undefined : new Date(task.deleted);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Task Priority (0, 1, 2, or 3)
|
|
188
|
+
* @type {int}
|
|
189
|
+
*/
|
|
190
|
+
this.priority = task.priority?.toString() === 'N' ? 0 : parseInt(task.priority);
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Task Postponed Flag
|
|
194
|
+
* @type {boolean}
|
|
195
|
+
*/
|
|
196
|
+
this.postponed = task.postponed?.toString() === '1';
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Task Time Estimate
|
|
200
|
+
* @type {string|undefined}
|
|
201
|
+
*/
|
|
202
|
+
this.estimate = task.estimate?.toString() === '' ? undefined : task.estimate;
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
// Assign Task Index
|
|
206
|
+
this._index = taskIds.getIndex(userId, this);
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Task recurring flag
|
|
210
|
+
* @type {boolean}
|
|
211
|
+
*/
|
|
212
|
+
this.isRecurring = series.rrule ? true : false;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Task subtask flag
|
|
216
|
+
* @type {boolean}
|
|
217
|
+
*/
|
|
218
|
+
this.isSubtask = series.parent_task_id != "" ? true : false;
|
|
219
|
+
|
|
220
|
+
/** Task parent task id
|
|
221
|
+
* @type {integer|undefined}
|
|
222
|
+
*/
|
|
223
|
+
this.parentTaskId = series.parent_task_id != "" ? parseFloat(series.parent_task_id) : undefined;
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* An index added to each RTMTask based on the `task_id`
|
|
231
|
+
* @type {int}
|
|
232
|
+
*/
|
|
233
|
+
get index() {
|
|
234
|
+
return this._index;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The `RTMList` this Task is in
|
|
239
|
+
* @type {RTMList}
|
|
240
|
+
*/
|
|
241
|
+
get list() {
|
|
242
|
+
if ( this._list === undefined ) {
|
|
243
|
+
throw "Tasks not loaded with associated Lists"
|
|
244
|
+
}
|
|
245
|
+
return this._list;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* All of the RTM TaskSeries properties
|
|
250
|
+
* @type {object}
|
|
251
|
+
*/
|
|
252
|
+
get props() {
|
|
253
|
+
let rtn = {};
|
|
254
|
+
for ( let key in this ) {
|
|
255
|
+
if ( this.hasOwnProperty(key) && key !== '_index' ) {
|
|
256
|
+
rtn[key] = this[key];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return rtn;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
module.exports = RTMTask;
|