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-08-19 12:20:38 +01:00
|
|
|
import { ProjectMember, ProjectMemberCursor, ProjectMembersPage } from '@/types/projectMembers';
|
2019-07-18 14:39:39 +01:00
|
|
|
import { RequestResponse } from '@/types/response';
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request.
|
2019-08-05 16:43:52 +01:00
|
|
|
export async function addProjectMembersRequest(projectId: string, emails: string[]): Promise<RequestResponse<null>> {
|
2019-02-20 13:33:56 +00:00
|
|
|
let result: RequestResponse<null> = {
|
2018-12-26 15:05:33 +00:00
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
2019-01-03 15:05:22 +00:00
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
mutation($projectId: String!, $emails:[String!]!) {
|
|
|
|
addProjectMembers(
|
|
|
|
projectID: $projectId,
|
|
|
|
email: $emails
|
|
|
|
) {id}
|
|
|
|
}`,
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
projectId: projectId,
|
|
|
|
emails: emails
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-26 15:05:33 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
2019-02-20 13:33:56 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
2019-08-05 16:43:52 +01:00
|
|
|
export async function deleteProjectMembersRequest(projectId: string, emails: string[]): Promise<RequestResponse<null>> {
|
2019-02-20 13:33:56 +00:00
|
|
|
let result: RequestResponse<null> = {
|
2018-12-26 15:05:33 +00:00
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
2018-12-26 15:05:33 +00:00
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
mutation($projectId: String!, $emails:[String!]!) {
|
|
|
|
deleteProjectMembers(
|
|
|
|
projectID: $projectId,
|
|
|
|
email: $emails
|
|
|
|
) {id}
|
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
projectId: projectId,
|
|
|
|
emails: emails
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-26 15:05:33 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
2019-02-20 13:33:56 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
2019-08-19 12:20:38 +01:00
|
|
|
export async function fetchProjectMembersRequest(projectId: string, cursor: ProjectMemberCursor): Promise<RequestResponse<ProjectMembersPage>> {
|
|
|
|
let result: RequestResponse<ProjectMembersPage> = {
|
2019-02-20 13:33:56 +00:00
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
2019-08-19 12:20:38 +01:00
|
|
|
data: new ProjectMembersPage()
|
2019-02-20 13:33:56 +00:00
|
|
|
};
|
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.query(
|
|
|
|
{
|
|
|
|
query: gql(`
|
2019-08-19 12:20:38 +01:00
|
|
|
query($projectId: String!, $limit: Int!, $search: String!, $page: Int!, $order: Int!, $orderDirection: Int!) {
|
|
|
|
project (
|
2019-08-05 16:43:52 +01:00
|
|
|
id: $projectId,
|
|
|
|
) {
|
2019-08-19 12:20:38 +01:00
|
|
|
members (
|
|
|
|
cursor: {
|
|
|
|
limit: $limit,
|
|
|
|
search: $search,
|
|
|
|
page: $page,
|
|
|
|
order: $order,
|
|
|
|
orderDirection: $orderDirection
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
projectMembers {
|
|
|
|
user {
|
|
|
|
id,
|
|
|
|
fullName,
|
|
|
|
shortName,
|
|
|
|
email
|
|
|
|
},
|
|
|
|
joinedAt
|
2019-08-05 16:43:52 +01:00
|
|
|
},
|
2019-08-19 12:20:38 +01:00
|
|
|
search,
|
|
|
|
limit,
|
|
|
|
order,
|
|
|
|
pageCount,
|
|
|
|
currentPage,
|
|
|
|
totalCount
|
2019-08-05 16:43:52 +01:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
}
|
2019-08-05 16:43:52 +01:00
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
projectId: projectId,
|
2019-08-19 12:20:38 +01:00
|
|
|
limit: cursor.limit,
|
|
|
|
search: cursor.search,
|
|
|
|
page: cursor.page,
|
|
|
|
order: cursor.order,
|
|
|
|
orderDirection: cursor.orderDirection,
|
2019-08-05 16:43:52 +01:00
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-26 15:05:33 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
2019-07-18 14:39:39 +01:00
|
|
|
result.data = getProjectMembersList(response.data.project.members);
|
2019-02-20 13:33:56 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
return result;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
2019-01-03 15:05:22 +00:00
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
function getProjectMembersList(projectMembers: any): ProjectMembersPage {
|
2019-07-18 14:39:39 +01:00
|
|
|
if (!projectMembers) {
|
2019-08-19 12:20:38 +01:00
|
|
|
return new ProjectMembersPage();
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
|
|
|
|
2019-08-19 12:20:38 +01:00
|
|
|
const projectMembersPage: ProjectMembersPage = new ProjectMembersPage();
|
|
|
|
projectMembersPage.projectMembers = projectMembers.projectMembers.map(key => new ProjectMember(key.user.fullName, key.user.shortName, key.user.email, key.joinedAt, key.user.id));
|
|
|
|
|
|
|
|
projectMembersPage.search = projectMembers.search;
|
|
|
|
projectMembersPage.limit = projectMembers.limit;
|
|
|
|
projectMembersPage.order = projectMembers.order;
|
|
|
|
projectMembersPage.orderDirection = projectMembers.orderDirection;
|
|
|
|
projectMembersPage.pageCount = projectMembers.pageCount;
|
|
|
|
projectMembersPage.currentPage = projectMembers.currentPage;
|
|
|
|
projectMembersPage.totalCount = projectMembers.totalCount;
|
|
|
|
|
|
|
|
return projectMembersPage;
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|