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

Commit e6301f8

Browse files
authored
Merge pull request #1 from dubisdev/v.0.0.3
V.0.0.3
2 parents d8a1184 + 65858e8 commit e6301f8

File tree

12 files changed

+219
-35
lines changed

12 files changed

+219
-35
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import IManager from "./IManager.js";
1+
import IManager from "./managers/IManager.js";
22

33
export default class TDSClient {
44
constructor(apiToken) {
@@ -18,6 +18,15 @@ export default class TDSClient {
1818
return await TypeManager.getAll();
1919
}
2020

21+
/**
22+
* Method for getting all todoist resources from one type (task, project, etc.) in an array with JSON content
23+
* The resource type is given by params
24+
*/
25+
async getAllJSON({ type = "task" } = {}) {
26+
const TypeManager = new IManager(type, this.headers);
27+
return await TypeManager.getAllJSON();
28+
}
29+
2130
/**
2231
* Method for getting today tasks
2332
*/
@@ -29,9 +38,10 @@ export default class TDSClient {
2938
/**
3039
* Method for creating todoist resources (task, project, etc.). The resource type ond object are given by params.
3140
* If no params, creates a NO_CONTENT task
41+
* Returns true if all ok, then false.
3242
*/
3343
create({ type = "task" } = {}, ObjectFromType) {
3444
const TypeManager = new IManager(type, this.headers);
35-
TypeManager.create(ObjectFromType);
45+
return TypeManager.create(ObjectFromType);
3646
}
3747
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import TasksManager from "./TasksManager.js";
2+
import ProjectsManager from "./ProjectsManager.js";
23
/**
34
* Interface for creating resources managers
45
*/
@@ -7,6 +8,8 @@ export default class IManager {
78
switch (type) {
89
case "task":
910
return new TasksManager({ headers });
11+
case "project":
12+
return new ProjectsManager({ headers });
1013
}
1114
}
1215
}

core/managers/ProjectsManager.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import Project from "../resources/Project.js";
2+
import axios from "axios";
3+
4+
export default class ProjectsManager {
5+
constructor({ headers }) {
6+
this.headers = headers;
7+
}
8+
9+
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+
});
17+
}
18+
19+
/**
20+
* returns an array with all projects
21+
*/
22+
async getAll() {
23+
let json = await getAllJson(this.headers);
24+
let arrayProjects = [];
25+
json.map((project) => {
26+
arrayProjects.push(project.name);
27+
});
28+
return arrayProjects;
29+
}
30+
31+
/**
32+
* returns an array with all projects JSON info
33+
*/
34+
async getAllJSON() {
35+
return await getAllJson(this.headers);
36+
}
37+
}
38+
39+
async function getAllJson(headers) {
40+
return await axios
41+
.get(`https://api.todoist.com/rest/v1/projects`, headers)
42+
.then((res = {}) => res.data);
43+
}
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Task from "../todoist_resources/Task.js";
1+
import Task from "../resources/Task.js";
22
import axios from "axios";
33

44
export default class TasksManager {
@@ -7,9 +7,13 @@ export default class TasksManager {
77
}
88

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

1519
/**
@@ -24,6 +28,13 @@ export default class TasksManager {
2428
return arrayTasks;
2529
}
2630

31+
/**
32+
* returns an array with all tasks JSON info
33+
*/
34+
async getAllJSON() {
35+
return await getAllJson(this.headers);
36+
}
37+
2738
/**
2839
* returns an array with all today tasks
2940
*/

core/resources/Project.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default class Project {
2+
constructor({
3+
name = "_No_Project_Name_Provided_",
4+
parent_id,
5+
color,
6+
favorite,
7+
} = {}) {
8+
this.name = name;
9+
//these are optional
10+
this.parent_id = parent_id;
11+
this.color = color;
12+
this.favorite = favorite;
13+
}
14+
}

core/resources/Section.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default class Section {
2+
constructor({ name = "_No_Section_Name_Provided_", parent_id, order } = {}) {
3+
this.name = name;
4+
//these are optional
5+
this.parent_id = parent_id;
6+
this.order = order;
7+
}
8+
}

core/resources/Task.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default class Task {
2+
constructor({
3+
content = "_NO_CONTENT_",
4+
project_id,
5+
section_id,
6+
parent_id,
7+
order,
8+
label_ids,
9+
priority,
10+
due_string,
11+
due_date,
12+
due_datetime,
13+
due_lang,
14+
assignee,
15+
} = {}) {
16+
this.content = content;
17+
//these are optional
18+
this.project_id = project_id;
19+
this.section_id = section_id;
20+
this.parent_id = parent_id;
21+
this.order = order;
22+
this.label_ids = label_ids;
23+
this.priority = priority;
24+
this.due_string = due_string;
25+
this.due_date = due_date;
26+
this.due_datetime = due_datetime;
27+
this.due_lang = due_lang;
28+
this.assignee = assignee;
29+
}
30+
}

core/resources/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Task from "./Task.js";
2+
import Project from "./Project.js";
3+
import Section from "./Section.js";
4+
5+
export { Task, Project, Section };

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import TDSClient from "./api_services/tds_client.js";
2-
import Task from "./todoist_resources/Task.js";
3-
1+
import TDSClient from "./core/TDSClient.js";
42
export default TDSClient;
5-
export { Task };
3+
4+
export { Task, Project } from "./core/resources/index.js";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "todoist-rest-client",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A simple todoist-rest-api client",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)