2018-12-10 17:32:15 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import apollo from '@/utils/apolloManager';
|
2018-12-18 14:43:23 +00:00
|
|
|
import gql from 'graphql-tag';
|
2018-12-10 17:32:15 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
|
|
|
export async function addProjectMember(userID: string, projectID: string): Promise<any> {
|
2018-12-18 14:43:23 +00:00
|
|
|
let response: any = null;
|
|
|
|
try {
|
2018-12-12 16:19:20 +00:00
|
|
|
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
|
|
|
),
|
2018-12-18 14:43:23 +00:00
|
|
|
fetchPolicy: 'no-cache',
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
|
|
|
);
|
2018-12-18 14:43:23 +00:00
|
|
|
} catch (e) {
|
2018-12-12 16:19:20 +00:00
|
|
|
// TODO: replace with popup in future
|
2018-12-18 14:43:23 +00:00
|
|
|
console.error(e);
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
return response;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
|
|
|
export async function deleteProjectMember(userID: string, projectID: string): Promise<any> {
|
2018-12-18 14:43:23 +00:00
|
|
|
let response: any = null;
|
|
|
|
try {
|
|
|
|
response = await apollo.mutate(
|
2018-12-12 16:19:20 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
),
|
2018-12-18 14:43:23 +00:00
|
|
|
fetchPolicy: 'no-cache',
|
2018-12-12 16:19:20 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
return response;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
2018-12-20 16:18:08 +00:00
|
|
|
export async function fetchProjectMembers(projectID: string, limit: string, offset: string): Promise<any> {
|
2018-12-18 14:43:23 +00:00
|
|
|
let response: any = null;
|
|
|
|
try {
|
|
|
|
response = await apollo.query(
|
2018-12-12 16:19:20 +00:00
|
|
|
{
|
|
|
|
query: gql(`
|
2018-12-10 17:32:15 +00:00
|
|
|
query {
|
|
|
|
project(
|
|
|
|
id: "${projectID}",
|
|
|
|
) {
|
2018-12-20 16:18:08 +00:00
|
|
|
members(limit: ${limit}, offset: ${offset}) {
|
2018-12-10 17:32:15 +00:00
|
|
|
user {
|
2018-12-12 16:19:20 +00:00
|
|
|
id,
|
2018-12-10 17:32:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.error(e);
|
|
|
|
}
|
2018-12-10 17:32:15 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
return response;
|
2018-12-10 17:32:15 +00:00
|
|
|
}
|