2021-07-15 05:09:35 -04:00
|
|
|
import { DEFAULT_PER_PAGE } from '~/api';
|
2021-01-14 10:10:46 -05:00
|
|
|
import axios from '../lib/utils/axios_utils';
|
|
|
|
import { buildApiUrl } from './api_utils';
|
|
|
|
|
|
|
|
const GROUPS_PATH = '/api/:version/groups.json';
|
2021-06-14 11:09:48 -04:00
|
|
|
const DESCENDANT_GROUPS_PATH = '/api/:version/groups/:id/descendant_groups';
|
2021-01-14 10:10:46 -05:00
|
|
|
|
2021-06-14 11:09:48 -04:00
|
|
|
const axiosGet = (url, query, options, callback) => {
|
2021-01-14 10:10:46 -05:00
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: {
|
|
|
|
search: query,
|
|
|
|
per_page: DEFAULT_PER_PAGE,
|
|
|
|
...options,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2021-06-14 11:09:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export function getGroups(query, options, callback = () => {}) {
|
|
|
|
const url = buildApiUrl(GROUPS_PATH);
|
|
|
|
return axiosGet(url, query, options, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getDescendentGroups(parentGroupId, query, options, callback = () => {}) {
|
|
|
|
const url = buildApiUrl(DESCENDANT_GROUPS_PATH.replace(':id', parentGroupId));
|
|
|
|
return axiosGet(url, query, options, callback);
|
2021-01-14 10:10:46 -05:00
|
|
|
}
|