-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskPoster.js
More file actions
41 lines (37 loc) · 1.03 KB
/
Copy pathTaskPoster.js
File metadata and controls
41 lines (37 loc) · 1.03 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
var TaskPoster = function() {
this.failList = "";
self = this;
this.postChecklistTask = function(task, notes, checklist) {
var taskObj = self.makeTaskObj(task, notes)
var taskId = self.postTasks([taskObj]);
checklist.forEach(function(item) {
var postChecklistResult = postHabApi("/api/v3/tasks/" + taskId + "/checklist", item);
if (!postChecklistResult) {
self.addToFailList(item["text"]);
}
});
}
this.postTasks = function(tasks) {
var postResult = postHabApi("/api/v3/tasks/user", tasks);
if (postResult) {
return postResult["data"]["id"];
} else {
tasks.forEach(function(task) {
self.addToFailList(task["text"]);
});
return null;
}
}
this.makeTaskObj = function(text, notes) {
return {
"text": text,
"type": "todo",
"priority": "1.5",
"notes": notes,
"collapseChecklist": true,
}
}
this.addToFailList = function(fail) {
self.failList += "<" + fail + ">\n";
}
}