storj/web/satellite/src/api/projectMembers.ts
Nikolay Yurchenko 312fd5a5fd
[V3-963] Satellite team members add dialog (#935)
* Implemented team member add dialog without api.

* logic changed according to api

* added initial app reducer and team members deletion fixed
2018-12-26 17:05:33 +02:00

124 lines
2.8 KiB
TypeScript

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import apollo from '@/utils/apolloManager';
import gql from 'graphql-tag';
// Performs graqhQL request.
// Throws an exception if error occurs
export async function addProjectMembers(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,
data: null
};
try {
let response: any = await apollo.mutate(
{
mutation: gql(`
mutation {
addProjectMembers(
projectID: "${projectID}",
email: "${emails}"
) {id}
}`
),
fetchPolicy: 'no-cache',
}
);
if (response.errors) {
result.errorMessage = response.errors[0].message;
} else {
result.isSuccess = true;
}
} catch (e) {
result.errorMessage = e.message;
}
return result;
}
// Performs graqhQL request.
// Throws an exception if error occurs
export async function deleteProjectMembers(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,
data: null
};
try {
let response: any = await apollo.mutate(
{
mutation: gql(`
mutation {
deleteProjectMembers(
projectID: "${projectID}",
email: "${emails}"
) {id}
}`
),
fetchPolicy: 'no-cache',
}
);
if (response.errors) {
result.errorMessage = response.errors[0].message;
} else {
result.isSuccess = true;
}
} catch (e) {
result.errorMessage = e.message;
}
return result;
}
// Performs graqhQL request.
// Throws an exception if error occurs
export async function fetchProjectMembers(projectID: string, limit: string, offset: string): Promise<RequestResponse<TeamMemberModel[]>> {
let result: RequestResponse<TeamMemberModel[]> = {
errorMessage: '',
isSuccess: false,
data: []
};
try {
let response: any = await apollo.query(
{
query: gql(`
query {
project(
id: "${projectID}",
) {
members(limit: ${limit}, offset: ${offset}) {
user {
id,
firstName,
lastName,
email
},
joinedAt
}
}
}`
),
fetchPolicy: 'no-cache',
}
);
if (response.errors) {
result.errorMessage = response.errors[0].message;
} else {
result.isSuccess = true;
result.data = response.data.project.members;
}
} catch (e) {
result.errorMessage = e.message;
}
return result;
}