Newer
Older
Sonia Zorba
committed
const BASE_API_URL = process.env.VUE_APP_API_BASE_URL;
function apiRequest(url, data) {
Sonia Zorba
committed
loading(true);
return new Promise((resolve, reject) => {
fetch(url, data)
.then(response => {
Sonia Zorba
committed
loading(false);
if([200, 201, 204, 400].includes(response.status)) { // valid status codes
resolve(response.json());
} else {
response.json().then(jsonValue => dispatchApiErrorEvent(jsonValue));
}
})
.catch(error => {
Sonia Zorba
committed
loading(false);
dispatchApiErrorEvent(error);
});
});
}
function dispatchApiErrorEvent(error) {
let message;
if(error.message) {
message = error.message;
} else {
message = 'Generic error';
}
let event = new CustomEvent('apiError');
event.message = message;
document.dispatchEvent(event);
}
Sonia Zorba
committed
/* For loading animation */
function loading(value) {
let event = new CustomEvent('loading');
event.value = value;
document.dispatchEvent(event);
}
Sonia Zorba
committed
fetchHomePageModel (input) {
let url = BASE_API_URL
+ 'home?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchPanel (input) {
let url = BASE_API_URL
Sonia Zorba
committed
+ input.selectedTab
+ '?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
Sonia Zorba
committed
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
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
});
},
addGroup (newGroupName, input) {
let url = BASE_API_URL + 'group';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
newGroupName: newGroupName,
parentGroupId: input.selectedGroupId,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
},
renameGroup (groupId, newGroupName, input) {
let url = BASE_API_URL + 'group/' + groupId;
return apiRequest(url, {
method: 'PUT',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
newGroupName: newGroupName,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
},
removeGroup (groupId, input) {
let url = BASE_API_URL + 'group/' + groupId
+ '?paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
searchUser (searchInput) {
let url = BASE_API_URL + 'users?search=' + searchInput;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
addPermission (userId, permission, input) {
let url = BASE_API_URL + 'permission';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
},
getPermission (groupId, userId) {
let url = BASE_API_URL + 'permission?groupId=' + groupId + '&userId=' + userId;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
addMember (userId, permission, input) {
let url = BASE_API_URL + 'member';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
},
removeMember (userId, removeAlsoPermission, input) {
let url = BASE_API_URL + 'member'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&removeAlsoPermission=' + removeAlsoPermission
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
removePermission (userId, input) {
let url = BASE_API_URL + 'permission'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});