Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
116 lines (105 loc) · 3.14 KB
/
Copy pathmain.js
File metadata and controls
116 lines (105 loc) · 3.14 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const { create } = require('axios');
class ClickUp {
constructor(token, {
baseURL = 'https://api.clickup.com/api/v2' // Base URL For ClickUp API
} = {}) {
this.client = create({ baseURL, headers: {
'Content-Type': 'application/json',
'Authorization': token
}
})
}
/**
* Creates a task in a specific list
* @param {Number} listId list to create the task in
* @param {Object} task_data object including all the values and settings of the task
* @returns {Object} returns a object with all the data from the request
*/
async createTask(listId, task_data) {
try {
const { data } = await this.client.post(`/list/${listId}/task`, {
...task_data
})
return data
} catch (error) {
console.log(error.message)
}
}
/**
* deletes a task given the task id
* @param {Number} taskId
* @returns {Object} returns a object with all the data from the request
*/
async deleteTask(taskId) {
try {
const { data } = await this.client.delete(`/task/${taskId}`, {
})
return data;
} catch (error) {
console.log(error.message)
}
}
/**
* Comments on a task by id
* @param {Number} taskId
* @param {Object} comment_data
* @returns {Object} returns a object with all the data from the request
*/
async commentOnTask(taskId, comment_data) {
try {
const { data } = await this.client.post(`/task/${taskId}/comment`, {
...comment_data
})
return data;
} catch (error) {
console.log(error.message)
}
}
/**
* Updates a task by the id
* @param {Number} taskId
* @param {Object} task_data
* @returns {Object} returns a object with all the data from the request
*/
async updateTask(taskId, task_data) {
try {
const { data } = await this.client.put(`/task/${taskId}`, {
...task_data
})
return data;
} catch (error) {
console.log(error.message)
}
}
// 1.1.0
/**
* Grabs a task by task id
* @param {Number} taskId the task id to get
* @param {Boolean} include_subtasks include the sub task or not
* @returns {Object} returns a object with all the data from the request
*/
async getTask(taskId, include_subtasks) {
try {
const { data } = await this.client.get(`/task/${taskId}?include_subtasks=${include_subtasks}`)
return data;
} catch (error) {
console.log(error.message)
}
}
/**
*
* @param {Number} listId
* @param {Object} filters
* @returns
*/
async getTasks(listId, filters) {
const querys = new URLSearchParams(filters).toString();
try {
const { data } = await this.client.get(`/list/${listId}/task?${querys}`)
return data;
} catch (error) {
console.log(error.message)
}
}
}
module.exports = ClickUp;