2019-09-04 03:45:28 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-05-05 02:34:56 +00:00
|
|
|
|
|
|
|
export default class GroupsService {
|
|
|
|
constructor(endpoint) {
|
2019-09-04 03:45:28 +00:00
|
|
|
this.endpoint = endpoint;
|
2017-05-05 02:34:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 08:36:25 +00:00
|
|
|
getGroups(parentId, page, filterGroups, sort, archived) {
|
2019-09-04 03:45:28 +00:00
|
|
|
const params = {};
|
2017-05-12 08:36:08 +00:00
|
|
|
|
|
|
|
if (parentId) {
|
2019-09-04 03:45:28 +00:00
|
|
|
params.parent_id = parentId;
|
2017-06-01 21:47:39 +00:00
|
|
|
} else {
|
|
|
|
// Do not send the following param for sub groups
|
|
|
|
if (page) {
|
2019-09-04 03:45:28 +00:00
|
|
|
params.page = page;
|
2017-06-01 21:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filterGroups) {
|
2019-09-04 03:45:28 +00:00
|
|
|
params.filter = filterGroups;
|
2017-06-01 21:47:39 +00:00
|
|
|
}
|
2017-06-06 05:06:08 +00:00
|
|
|
|
|
|
|
if (sort) {
|
2019-09-04 03:45:28 +00:00
|
|
|
params.sort = sort;
|
2017-06-06 05:06:08 +00:00
|
|
|
}
|
2017-10-13 08:36:25 +00:00
|
|
|
|
|
|
|
if (archived) {
|
2019-09-04 03:45:28 +00:00
|
|
|
params.archived = archived;
|
2017-10-13 08:36:25 +00:00
|
|
|
}
|
2017-05-12 08:36:08 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 03:45:28 +00:00
|
|
|
return axios.get(this.endpoint, { params });
|
2017-05-05 02:34:56 +00:00
|
|
|
}
|
2017-05-30 08:12:06 +00:00
|
|
|
|
2017-06-01 01:25:23 +00:00
|
|
|
// eslint-disable-next-line class-methods-use-this
|
2017-05-30 08:12:06 +00:00
|
|
|
leaveGroup(endpoint) {
|
2019-09-04 03:45:28 +00:00
|
|
|
return axios.delete(endpoint);
|
2017-05-30 08:12:06 +00:00
|
|
|
}
|
2017-05-05 02:34:56 +00:00
|
|
|
}
|