-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectsApiHandler.js
More file actions
63 lines (54 loc) · 1.93 KB
/
ProjectsApiHandler.js
File metadata and controls
63 lines (54 loc) · 1.93 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const axios = require('axios');
const { response } = require('express');
class ProjectsApiHandler {
constructor() { }
async getAllProjects() {
// Returns an array with all existent projects in the following format:
// {id, project name}.
const data = await axios.get('https://desolate-journey-04573.herokuapp.com/api/project')
let res = []
for (let proj of data.data.results) {
res.push({
id: proj.id,
name: proj.name
})
}
return res
}
async getAllTasks() {
// Returns an array with all existent tasks in the following format:
// {id, task name}.
const data = await axios.get('https://desolate-journey-04573.herokuapp.com/api/tasks')
let res = []
for (let task of data.data.results) {
res.push({
id: task.id,
name: task.name,
id_project: task.id_project
})
}
return res
}
async getAllTasksFromProject(projectId) {
// Returns an array with all existent tasks which correspond to project
// with id 'projectId' in the following format:
// {id, task name}.
const data = await axios.get(`https://desolate-journey-04573.herokuapp.com/api/task/set/${projectId}`)
let res = []
for (let task of data.data.results) {
res.push({
id: task.id,
name: task.name
})
}
return res
}
async getProjectIdAssociatedToTask(taskId) {
// Recieves a task id 'taskId' and returns the id of the project in which
// the task was registered.
const data = await axios.get(`https://desolate-journey-04573.herokuapp.com/api/task/${taskId}`)
if (!data.data.results[0]) return undefined
return data.data.results[0].id_project
}
}
module.exports = ProjectsApiHandler