debian-mirror-gitlab/app/assets/javascripts/sidebar/services/sidebar_service.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-04-23 21:23:45 +05:30
import { TYPENAME_USER } from '~/graphql_shared/constants';
2021-03-11 19:13:27 +05:30
import { convertToGraphQLId } from '~/graphql_shared/utils';
2020-10-24 23:57:45 +05:30
import createGqClient, { fetchPolicies } from '~/lib/graphql';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
import reviewerRereviewMutation from '../queries/reviewer_rereview.mutation.graphql';
2020-04-08 14:13:33 +05:30
export const gqClient = createGqClient(
{},
{
fetchPolicy: fetchPolicies.NO_CACHE,
},
);
2017-08-17 22:00:37 +05:30
export default class SidebarService {
2018-03-17 18:26:18 +05:30
constructor(endpointMap) {
2017-08-17 22:00:37 +05:30
if (!SidebarService.singleton) {
2018-03-17 18:26:18 +05:30
this.endpoint = endpointMap.endpoint;
this.moveIssueEndpoint = endpointMap.moveIssueEndpoint;
this.projectsAutocompleteEndpoint = endpointMap.projectsAutocompleteEndpoint;
2020-04-08 14:13:33 +05:30
this.fullPath = endpointMap.fullPath;
this.iid = endpointMap.iid;
2021-04-17 20:07:23 +05:30
this.issuableType = endpointMap.issuableType;
2017-08-17 22:00:37 +05:30
SidebarService.singleton = this;
}
2022-08-13 15:12:31 +05:30
// eslint-disable-next-line no-constructor-return
2017-08-17 22:00:37 +05:30
return SidebarService.singleton;
}
get() {
2022-11-25 23:54:43 +05:30
return axios.get(this.endpoint);
2021-04-17 20:07:23 +05:30
}
2017-08-17 22:00:37 +05:30
update(key, data) {
2019-12-04 20:38:33 +05:30
return axios.put(this.endpoint, { [key]: data });
2017-08-17 22:00:37 +05:30
}
2018-03-17 18:26:18 +05:30
getProjectsAutocomplete(searchTerm) {
2019-12-04 20:38:33 +05:30
return axios.get(this.projectsAutocompleteEndpoint, {
2018-03-17 18:26:18 +05:30
params: {
search: searchTerm,
},
});
}
moveIssue(moveToProjectId) {
2019-12-04 20:38:33 +05:30
return axios.post(this.moveIssueEndpoint, {
2018-03-17 18:26:18 +05:30
move_to_project_id: moveToProjectId,
});
}
2021-03-11 19:13:27 +05:30
requestReview(userId) {
return gqClient.mutate({
mutation: reviewerRereviewMutation,
variables: {
2023-04-23 21:23:45 +05:30
userId: convertToGraphQLId(TYPENAME_USER, `${userId}`),
2021-03-11 19:13:27 +05:30
projectPath: this.fullPath,
iid: this.iid.toString(),
},
});
}
2017-08-17 22:00:37 +05:30
}