-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
boards.js
165 lines (152 loc) · 2.99 KB
/
boards.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// packges
import axios from "axios";
// store
import store from "../store";
/**
* Get public boards
*
* @param {number} page page number default to 1
* @param {string} sort sort type asc or desc
*
* @returns {object} response
*/
export const getPublicBoards = async (page = 1, limit, sort = "desc") => {
return await axios({
method: "GET",
url: "/api/v1/boards",
params: {
page,
limit,
created: sort
}
});
};
/**
* Get all boards
*
* @param {number} page page number default to 1
* @param {string} sort sort type asc or desc
*
* @returns {object} response
*/
export const getAllBoards = async (page = 1, limit, sort = "desc") => {
return await axios({
method: "GET",
url: "/api/v1/boards/get",
params: {
page,
limit,
created: sort
}
});
};
/**
* Get board by URL
*
* @param {string} url board url
*
* @returns {object} response
*/
export const getBoardByUrl = async url => {
return await axios({
method: "GET",
url: `/api/v1/boards/${url}`
});
};
/**
* Search board by name
*
* @param {string} name board name
*
* @returns {object} response
*/
export const searchBoard = async name => {
const token = store.getters["user/getAuthToken"];
return await axios({
method: "GET",
url: `/api/v1/boards/search/${name}`,
headers: {
Authorization: `Bearer ${token}`
}
});
};
/**
* Create new board
*
* @returns {object} response
*/
export const createBoard = async () => {
const token = store.getters["user/getAuthToken"];
return await axios({
method: "POST",
url: "/api/v1/boards",
headers: {
Authorization: `Bearer ${token}`
}
});
};
/**
* Update board
*
* @param {object} board update board data
* @param {string} board.name board name
* @param {string} board.url board url
* @param {string} board.color board color
* @param {boolean} board.view_voters view voters in this board
* @param {boolean} board.display display board on the site
*
* @returns {object} response
*/
export const updateBoard = async board => {
const token = store.getters["user/getAuthToken"];
return await axios({
method: "PATCH",
url: "/api/v1/boards",
data: {
...board
},
headers: {
Authorization: `Bearer ${token}`
}
});
};
/**
* delete board
*
* @param {string} id board id
*
* @returns {object} response
*/
export const deleteBoard = async id => {
const token = store.getters["user/getAuthToken"];
return await axios({
method: "DELETE",
url: "/api/v1/boards",
data: {
id
},
headers: {
Authorization: `Bearer ${token}`
}
});
};
/**
* Check board name
*
* @param {string} name board name
*
* @returns {object} response
*/
export const checkBoardName = async name => {
const token = store.getters["user/getAuthToken"];
return await axios({
method: "POST",
url: "/api/v1/boards/check-name",
data: {
name
},
headers: {
Authorization: `Bearer ${token}`
}
});
};