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

Commit b89c020

Browse files
committed
changed project structure
1 parent d8a1184 commit b89c020

File tree

8 files changed

+58
-6
lines changed

8 files changed

+58
-6
lines changed
Lines changed: 1 addition & 1 deletion
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) {
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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
axios
11+
.post(`https://api.todoist.com/rest/v1/projects`, project, this.headers)
12+
.then(() => true)
13+
.catch((err) => console.error(err));
14+
}
15+
16+
/**
17+
* returns an array with all projects
18+
*/
19+
async getAll() {
20+
let json = await getAllJson(this.headers);
21+
let arrayProjects = [];
22+
json.map((project) => {
23+
arrayProjects.push(project.name);
24+
});
25+
return arrayProjects;
26+
}
27+
}
28+
29+
async function getAllJson(headers) {
30+
return await axios
31+
.get(`https://api.todoist.com/rest/v1/projects`, headers)
32+
.then((res = {}) => res.data);
33+
}
Lines changed: 1 addition & 1 deletion
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 {

core/resources/Project.js

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

core/resources/index.js

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

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";

0 commit comments

Comments
 (0)