2018-12-10 17:32:15 +00:00
|
|
|
// 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 addProjectMember(userID: string, projectID: string): Promise<any> {
|
2018-12-12 16:19:20 +00:00
|
|
|
let response = null;
|
|
|
|
try{
|
|
|
|
response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
mutation {
|
|
|
|
addProjectMember(
|
|
|
|
projectID: "${projectID}",
|
|
|
|
userID: "${userID}"
|
|
|
|
) {id}
|
|
|
|
}`
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}catch (e) {
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
|
|
|
export async function deleteProjectMember(userID: string, projectID: string): Promise<any> {
|
2018-12-12 16:19:20 +00:00
|
|
|
let response = null;
|
|
|
|
try {
|
|
|
|
response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
mutation {
|
|
|
|
deleteProjectMember(
|
|
|
|
projectID: "${projectID}",
|
|
|
|
userID: "${userID}"
|
|
|
|
) {id}
|
|
|
|
}`
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
|
|
|
export async function fetchProjectMembers(projectID: string): Promise<any> {
|
2018-12-12 16:19:20 +00:00
|
|
|
let response = null;
|
|
|
|
try {
|
|
|
|
response = await apollo.query(
|
|
|
|
{
|
|
|
|
query: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
query {
|
|
|
|
project(
|
|
|
|
id: "${projectID}",
|
|
|
|
) {
|
|
|
|
members {
|
|
|
|
user {
|
2018-12-12 16:19:20 +00:00
|
|
|
id,
|
2018-12-10 17:32:15 +00:00
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
email,
|
|
|
|
company {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
},
|
|
|
|
joinedAt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
2018-12-12 16:19:20 +00:00
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|