2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-10 17:32:15 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import apollo from '@/utils/apolloManager';
|
2018-12-18 14:43:23 +00:00
|
|
|
import gql from 'graphql-tag';
|
2019-01-10 14:44:15 +00:00
|
|
|
import { ProjectMemberSortByEnum } from '@/utils/constants/ProjectMemberSortEnum';
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function addProjectMembersRequest(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
|
2018-12-26 15:05:33 +00:00
|
|
|
let result: RequestResponse<null> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
|
|
|
};
|
2019-01-03 15:05:22 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
try {
|
2018-12-26 15:05:33 +00:00
|
|
|
let response: any = await apollo.mutate(
|
2018-12-12 16:19:20 +00:00
|
|
|
{
|
|
|
|
mutation: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
mutation {
|
2018-12-26 15:05:33 +00:00
|
|
|
addProjectMembers(
|
2018-12-10 17:32:15 +00:00
|
|
|
projectID: "${projectID}",
|
2019-01-03 15:05:22 +00:00
|
|
|
email: [${prepareEmailList(emails)}]
|
2018-12-10 17:32:15 +00:00
|
|
|
) {id}
|
2019-01-03 15:05:22 +00:00
|
|
|
}`,
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
2018-12-18 14:43:23 +00:00
|
|
|
fetchPolicy: 'no-cache',
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
|
|
|
);
|
2018-12-26 15:05:33 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
}
|
2018-12-18 14:43:23 +00:00
|
|
|
} catch (e) {
|
2018-12-26 15:05:33 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-26 15:05:33 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function deleteProjectMembersRequest(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
|
2018-12-26 15:05:33 +00:00
|
|
|
let result: RequestResponse<null> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
|
|
|
};
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
try {
|
2018-12-26 15:05:33 +00:00
|
|
|
let response: any = await apollo.mutate(
|
2018-12-12 16:19:20 +00:00
|
|
|
{
|
|
|
|
mutation: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
mutation {
|
2018-12-26 15:05:33 +00:00
|
|
|
deleteProjectMembers(
|
2018-12-10 17:32:15 +00:00
|
|
|
projectID: "${projectID}",
|
2019-01-03 15:05:22 +00:00
|
|
|
email: [${prepareEmailList(emails)}]
|
2018-12-10 17:32:15 +00:00
|
|
|
) {id}
|
|
|
|
}`
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
2018-12-18 14:43:23 +00:00
|
|
|
fetchPolicy: 'no-cache',
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
|
|
|
);
|
2018-12-26 15:05:33 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
}
|
2018-12-12 16:19:20 +00:00
|
|
|
} catch (e) {
|
2018-12-26 15:05:33 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-26 15:05:33 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
2019-01-10 14:44:15 +00:00
|
|
|
export async function fetchProjectMembersRequest(projectID: string, limit: string, offset: string, sortBy: ProjectMemberSortByEnum, searchQuery: string): Promise<RequestResponse<TeamMemberModel[]>> {
|
2018-12-26 15:05:33 +00:00
|
|
|
let result: RequestResponse<TeamMemberModel[]> = {
|
2019-01-10 14:44:15 +00:00
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: []
|
2018-12-26 15:05:33 +00:00
|
|
|
};
|
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
try {
|
2018-12-26 15:05:33 +00:00
|
|
|
let response: any = await apollo.query(
|
2018-12-12 16:19:20 +00:00
|
|
|
{
|
|
|
|
query: gql(`
|
2018-12-26 15:05:33 +00:00
|
|
|
query {
|
|
|
|
project(
|
|
|
|
id: "${projectID}",
|
|
|
|
) {
|
2019-01-10 14:44:15 +00:00
|
|
|
members(limit: ${limit}, offset: ${offset}, order: ${sortBy}, search: "${searchQuery}") {
|
2018-12-26 15:05:33 +00:00
|
|
|
user {
|
|
|
|
id,
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
email
|
|
|
|
},
|
|
|
|
joinedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
2018-12-18 14:43:23 +00:00
|
|
|
fetchPolicy: 'no-cache',
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
|
|
|
);
|
2018-12-26 15:05:33 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
result.data = response.data.project.members;
|
|
|
|
}
|
2018-12-12 16:19:20 +00:00
|
|
|
} catch (e) {
|
2018-12-26 15:05:33 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-26 15:05:33 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
2019-01-03 15:05:22 +00:00
|
|
|
|
|
|
|
function prepareEmailList(emails: string[]): string {
|
|
|
|
let emailString: string = '';
|
|
|
|
|
|
|
|
emails.forEach(email => {
|
|
|
|
emailString += `"${email}", `;
|
|
|
|
});
|
|
|
|
|
|
|
|
return emailString;
|
|
|
|
}
|