2021-09-30 23:02:18 +05:30
|
|
|
import { DEFAULT_PER_PAGE } from '~/api';
|
2021-03-08 18:12:59 +05:30
|
|
|
import axios from '../lib/utils/axios_utils';
|
|
|
|
import { buildApiUrl } from './api_utils';
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
const GROUP_PATH = '/api/:version/groups/:id';
|
2021-03-08 18:12:59 +05:30
|
|
|
const GROUPS_PATH = '/api/:version/groups.json';
|
2021-09-04 01:27:46 +05:30
|
|
|
const DESCENDANT_GROUPS_PATH = '/api/:version/groups/:id/descendant_groups';
|
2023-01-13 00:05:48 +05:30
|
|
|
const GROUP_TRANSFER_LOCATIONS_PATH = 'api/:version/groups/:id/transfer_locations';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const axiosGet = (url, query, options, callback) => {
|
2021-03-08 18:12:59 +05:30
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: {
|
|
|
|
search: query,
|
|
|
|
per_page: DEFAULT_PER_PAGE,
|
|
|
|
...options,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2021-09-04 01:27:46 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
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-03-08 18:12:59 +05:30
|
|
|
}
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
export function updateGroup(groupId, data = {}) {
|
|
|
|
const url = buildApiUrl(GROUP_PATH).replace(':id', groupId);
|
|
|
|
|
|
|
|
return axios.put(url, data);
|
|
|
|
}
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
export const getGroupTransferLocations = (groupId, params = {}) => {
|
|
|
|
const url = buildApiUrl(GROUP_TRANSFER_LOCATIONS_PATH).replace(':id', groupId);
|
|
|
|
const defaultParams = { per_page: DEFAULT_PER_PAGE };
|
|
|
|
|
|
|
|
return axios.get(url, { params: { ...defaultParams, ...params } });
|
|
|
|
};
|