Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 456d853

Browse files
authored
Merge pull request #2 from dubisdev/v0.0.4
V0.0.4
2 parents 68ab815 + 69adc7c commit 456d853

File tree

4 files changed

+109
-22
lines changed

4 files changed

+109
-22
lines changed

core/TDSClient.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class TDSClient {
1919
}
2020

2121
/**
22-
* Method for getting all todoist resources from one type (task, project, etc.) in an array with JSON content
22+
* Method for getting all todoist resources jsons from one type (task, project, etc.).
2323
* The resource type is given by params
2424
*/
2525
async getAllJSON({ type = "task" } = {}) {
@@ -28,7 +28,7 @@ export default class TDSClient {
2828
}
2929

3030
/**
31-
* Method for getting today tasks
31+
* Method for getting today tasks names
3232
*/
3333
async getTodayTasks() {
3434
const TypeManager = new IManager("task", this.headers);
@@ -44,4 +44,34 @@ export default class TDSClient {
4444
const TypeManager = new IManager(type, this.headers);
4545
return TypeManager.create(ObjectFromType);
4646
}
47+
48+
/**
49+
* Method for getting today tasks json
50+
*/
51+
async getTodayTasksJSON() {
52+
const TypeManager = new IManager("task", this.headers);
53+
return await TypeManager.getTodayJSON();
54+
}
55+
56+
/**
57+
* Method for getting a todoist resource from one type (task, project, etc.) by id.
58+
* The resource type is given by params.
59+
*/
60+
async get({ type, id } = {}) {
61+
const TypeManager = new IManager(type, this.headers);
62+
return await TypeManager.get(id);
63+
}
64+
65+
/**
66+
* Method for creating todoist resources (task, project, etc.). The resource type ond object are given by params.
67+
* If no params, creates a NO_CONTENT task
68+
*/
69+
async completeTask({ TaskObject = {}, id }) {
70+
const TypeManager = new IManager("task", this.headers);
71+
if (TaskObject.id) {
72+
return await TypeManager.completeTask(TaskObject.id);
73+
} else {
74+
return await TypeManager.completeTask(id);
75+
}
76+
}
4777
}

core/managers/ProjectsManager.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ export default class ProjectsManager {
77
}
88

99
create(project = new Project()) {
10-
return axios
11-
.post(`https://api.todoist.com/rest/v1/projects`, project, this.headers)
12-
.then(() => true)
13-
.catch((err) => {
14-
console.log(err);
15-
return false;
16-
});
10+
axios.post(
11+
`https://api.todoist.com/rest/v1/projects`,
12+
project,
13+
this.headers
14+
);
1715
}
1816

1917
/**
2018
* returns an array with all projects
2119
*/
2220
async getAll() {
23-
let json = await getAllJson(this.headers);
21+
let json = await getAllJSON(this.headers);
2422
let arrayProjects = [];
2523
json.map((project) => {
2624
arrayProjects.push(project.name);
@@ -34,10 +32,25 @@ export default class ProjectsManager {
3432
async getAllJSON() {
3533
return await getAllJson(this.headers);
3634
}
35+
36+
/**
37+
* returns the json of a project
38+
*/
39+
async get(id) {
40+
let project = await getOneJSON(id, this.headers);
41+
return project;
42+
}
43+
3744
}
3845

39-
async function getAllJson(headers) {
46+
async function getAllJSON(headers) {
4047
return await axios
4148
.get(`https://api.todoist.com/rest/v1/projects`, headers)
4249
.then((res = {}) => res.data);
4350
}
51+
52+
async function getOneJSON(id, headers) {
53+
return await axios
54+
.get(`https://api.todoist.com/rest/v1/projects/${id}`, headers)
55+
.then((res = {}) => res.data);
56+
}

core/managers/TasksManager.js

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,14 @@ export default class TasksManager {
77
}
88

99
create(task = new Task()) {
10-
return axios
11-
.post(`https://api.todoist.com/rest/v1/tasks`, task, this.headers)
12-
.then(() => true)
13-
.catch((err) => {
14-
console.log(err);
15-
return false;
16-
});
10+
axios.post(`https://api.todoist.com/rest/v1/tasks`, task, this.headers);
1711
}
1812

1913
/**
2014
* returns an array with all today tasks
2115
*/
2216
async getAll() {
23-
let json = await getAllJson(this.headers);
17+
let json = await getAllJSON(this.headers);
2418
let arrayTasks = [];
2519
json.map((task) => {
2620
arrayTasks.push(task.content);
@@ -35,11 +29,18 @@ export default class TasksManager {
3529
return await getAllJson(this.headers);
3630
}
3731

32+
/**
33+
* returns an array with all today tasks
34+
*/
35+
async getAllJSON() {
36+
return await getAllJSON(this.headers);
37+
}
38+
3839
/**
3940
* returns an array with all today tasks
4041
*/
4142
async getToday() {
42-
let json = await getAllJson(this.headers);
43+
let json = await getAllJSON(this.headers);
4344
let arrayTasks = [];
4445

4546
let todayTasksJson = json
@@ -54,10 +55,49 @@ export default class TasksManager {
5455

5556
return arrayTasks;
5657
}
58+
59+
/**
60+
* returns an array with all today tasks
61+
*/
62+
async getTodayJSON() {
63+
let json = await getAllJSON(this.headers);
64+
65+
let todayTasksJson = json
66+
.filter((task) => task.due !== undefined)
67+
.filter(
68+
(task) => task.due.date === new Date().toISOString().substring(0, 10)
69+
);
70+
71+
return todayTasksJson;
72+
}
73+
74+
/**
75+
* returns a JSON with a task
76+
*/
77+
async get(id) {
78+
return await getOneJSON(id, this.headers);
79+
}
80+
81+
/**
82+
* complete a task
83+
*/
84+
async completeTask(id) {
85+
return await axios.post(
86+
`https://api.todoist.com/rest/v1/tasks/${id}/close`,
87+
{},
88+
this.headers
89+
);
90+
}
5791
}
5892

59-
async function getAllJson(headers) {
93+
async function getAllJSON(headers) {
6094
return await axios
6195
.get(`https://api.todoist.com/rest/v1/tasks`, headers)
6296
.then((res = {}) => res.data);
6397
}
98+
99+
async function getOneJSON(id, headers) {
100+
return await axios
101+
.get(`https://api.todoist.com/rest/v1/tasks/${id}`, headers)
102+
.then((res = {}) => res.data);
103+
}

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ A todoist rest API client with:
66

77
## Implemented Features
88

9-
- get Today Tasks
9+
10+
- get Today Tasks (Names & JSON)
11+
- get a Task JSON by id
1012
- get All Tasks/Projects Names
1113
- get All Tasks/Projects JSON
1214
- create task/project (see examples)
15+
- complete task (see examples)
16+
1317

1418
I'll implement more features in the future like:
1519

0 commit comments

Comments
 (0)