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.
|
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
import { BaseGql } from '@/api/baseGql';
|
|
|
|
import { ProjectMember, ProjectMemberCursor, ProjectMembersApi, ProjectMembersPage } from '@/types/projectMembers';
|
|
|
|
|
|
|
|
export class ProjectMembersApiGql extends BaseGql implements ProjectMembersApi {
|
|
|
|
|
|
|
|
public async add(projectId: string, emails: string[]): Promise<void> {
|
|
|
|
const query =
|
|
|
|
`mutation($projectId: String!, $emails:[String!]!) {
|
|
|
|
addProjectMembers(
|
|
|
|
projectID: $projectId,
|
|
|
|
email: $emails
|
|
|
|
) {id}
|
|
|
|
}`;
|
|
|
|
|
|
|
|
const variables = {
|
|
|
|
projectId,
|
|
|
|
emails,
|
|
|
|
};
|
|
|
|
|
|
|
|
await this.mutate(query, variables);
|
2019-02-20 13:33:56 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
public async delete(projectId: string, emails: string[]): Promise<void> {
|
|
|
|
const query =
|
|
|
|
`mutation($projectId: String!, $emails:[String!]!) {
|
|
|
|
deleteProjectMembers(
|
|
|
|
projectID: $projectId,
|
|
|
|
email: $emails
|
|
|
|
) {id}
|
|
|
|
}`;
|
|
|
|
|
|
|
|
const variables = {
|
|
|
|
projectId,
|
|
|
|
emails,
|
|
|
|
};
|
|
|
|
|
|
|
|
await this.mutate(query, variables);
|
2019-02-20 13:33:56 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
public async get(projectId: string, cursor: ProjectMemberCursor): Promise<ProjectMembersPage> {
|
|
|
|
const query =
|
|
|
|
`query($projectId: String!, $limit: Int!, $search: String!, $page: Int!, $order: Int!, $orderDirection: Int!) {
|
|
|
|
project (
|
|
|
|
id: $projectId,
|
|
|
|
) {
|
|
|
|
members (
|
|
|
|
cursor: {
|
|
|
|
limit: $limit,
|
|
|
|
search: $search,
|
|
|
|
page: $page,
|
|
|
|
order: $order,
|
|
|
|
orderDirection: $orderDirection
|
|
|
|
}
|
2019-08-05 16:43:52 +01:00
|
|
|
) {
|
2019-08-20 13:57:43 +01:00
|
|
|
projectMembers {
|
|
|
|
user {
|
|
|
|
id,
|
|
|
|
fullName,
|
|
|
|
shortName,
|
|
|
|
email
|
2019-08-05 16:43:52 +01:00
|
|
|
},
|
2019-08-20 13:57:43 +01:00
|
|
|
joinedAt
|
|
|
|
},
|
|
|
|
search,
|
|
|
|
limit,
|
|
|
|
order,
|
|
|
|
pageCount,
|
|
|
|
currentPage,
|
|
|
|
totalCount
|
2019-04-05 16:08:14 +01:00
|
|
|
}
|
2019-08-20 13:57:43 +01:00
|
|
|
}
|
|
|
|
}`;
|
2019-04-05 16:08:14 +01:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
const variables = {
|
|
|
|
projectId: projectId,
|
|
|
|
limit: cursor.limit,
|
|
|
|
search: cursor.search,
|
|
|
|
page: cursor.page,
|
|
|
|
order: cursor.order,
|
|
|
|
orderDirection: cursor.orderDirection,
|
|
|
|
};
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
const response = await this.query(query, variables);
|
2019-01-03 15:05:22 +00:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
return this.getProjectMembersList(response.data.project.members);
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
private getProjectMembersList(projectMembers: any): ProjectMembersPage {
|
|
|
|
if (!projectMembers) {
|
|
|
|
return new ProjectMembersPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
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;
|
2019-08-19 12:20:38 +01:00
|
|
|
|
2019-08-20 13:57:43 +01:00
|
|
|
return projectMembersPage;
|
|
|
|
}
|
2019-07-18 14:39:39 +01:00
|
|
|
}
|