2021-09-30 23:02:18 +05:30
|
|
|
import { DEFAULT_PER_PAGE } from '~/api';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { __ } from '~/locale';
|
2021-03-08 18:12:59 +05:30
|
|
|
import axios from '../lib/utils/axios_utils';
|
|
|
|
import { buildApiUrl } from './api_utils';
|
|
|
|
|
|
|
|
const USER_COUNTS_PATH = '/api/:version/user_counts';
|
|
|
|
const USERS_PATH = '/api/:version/users.json';
|
|
|
|
const USER_PATH = '/api/:version/users/:id';
|
|
|
|
const USER_STATUS_PATH = '/api/:version/users/:id/status';
|
|
|
|
const USER_PROJECTS_PATH = '/api/:version/users/:id/projects';
|
|
|
|
const USER_POST_STATUS_PATH = '/api/:version/user/status';
|
2022-07-16 23:28:13 +05:30
|
|
|
const USER_FOLLOW_PATH = '/api/:version/users/:id/follow';
|
|
|
|
const USER_UNFOLLOW_PATH = '/api/:version/users/:id/unfollow';
|
2023-01-13 00:05:48 +05:30
|
|
|
const USER_ASSOCIATIONS_COUNT_PATH = '/api/:version/users/:id/associations_count';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
export function getUsers(query, options) {
|
|
|
|
const url = buildApiUrl(USERS_PATH);
|
|
|
|
return axios.get(url, {
|
|
|
|
params: {
|
|
|
|
search: query,
|
|
|
|
per_page: DEFAULT_PER_PAGE,
|
|
|
|
...options,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUser(id, options) {
|
|
|
|
const url = buildApiUrl(USER_PATH).replace(':id', encodeURIComponent(id));
|
|
|
|
return axios.get(url, {
|
|
|
|
params: options,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUserCounts() {
|
|
|
|
const url = buildApiUrl(USER_COUNTS_PATH);
|
|
|
|
return axios.get(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUserStatus(id, options) {
|
|
|
|
const url = buildApiUrl(USER_STATUS_PATH).replace(':id', encodeURIComponent(id));
|
|
|
|
return axios.get(url, {
|
|
|
|
params: options,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUserProjects(userId, query, options, callback) {
|
|
|
|
const url = buildApiUrl(USER_PROJECTS_PATH).replace(':id', userId);
|
|
|
|
const defaults = {
|
|
|
|
search: query,
|
|
|
|
per_page: DEFAULT_PER_PAGE,
|
|
|
|
};
|
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: { ...defaults, ...options },
|
|
|
|
})
|
|
|
|
.then(({ data }) => callback(data))
|
2021-09-30 23:02:18 +05:30
|
|
|
.catch(() =>
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: __('Something went wrong while fetching projects'),
|
|
|
|
}),
|
|
|
|
);
|
2021-03-08 18:12:59 +05:30
|
|
|
}
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
export function updateUserStatus({ emoji, message, availability, clearStatusAfter }) {
|
2021-03-08 18:12:59 +05:30
|
|
|
const url = buildApiUrl(USER_POST_STATUS_PATH);
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
return axios.patch(url, {
|
2021-03-08 18:12:59 +05:30
|
|
|
emoji,
|
|
|
|
message,
|
|
|
|
availability,
|
2021-04-29 21:17:54 +05:30
|
|
|
clear_status_after: clearStatusAfter,
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
}
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
export function followUser(userId) {
|
|
|
|
const url = buildApiUrl(USER_FOLLOW_PATH).replace(':id', encodeURIComponent(userId));
|
|
|
|
return axios.post(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function unfollowUser(userId) {
|
|
|
|
const url = buildApiUrl(USER_UNFOLLOW_PATH).replace(':id', encodeURIComponent(userId));
|
|
|
|
return axios.post(url);
|
|
|
|
}
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
export function associationsCount(userId) {
|
|
|
|
const url = buildApiUrl(USER_ASSOCIATIONS_COUNT_PATH).replace(':id', encodeURIComponent(userId));
|
|
|
|
return axios.get(url);
|
|
|
|
}
|