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';
|
|
|
|
|
|
|
|
const PROJECTS_PATH = '/api/:version/projects.json';
|
|
|
|
|
|
|
|
export function getProjects(query, options, callback = () => {}) {
|
|
|
|
const url = buildApiUrl(PROJECTS_PATH);
|
|
|
|
const defaults = {
|
|
|
|
search: query,
|
|
|
|
per_page: DEFAULT_PER_PAGE,
|
|
|
|
simple: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (gon.current_user_id) {
|
|
|
|
defaults.membership = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: Object.assign(defaults, options),
|
|
|
|
})
|
|
|
|
.then(({ data, headers }) => {
|
|
|
|
callback(data);
|
|
|
|
return { data, headers };
|
|
|
|
});
|
|
|
|
}
|