2018-11-28 09:43:43 +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-11-28 09:43:43 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request.
|
|
|
|
// Throws an exception if error occurs
|
|
|
|
export async function createProject(project: Project): Promise<any> {
|
2018-12-20 16:18:08 +00:00
|
|
|
let response: any = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
createProject(
|
|
|
|
input: {
|
|
|
|
name: "${project.name}",
|
|
|
|
description: "${project.description}",
|
|
|
|
isTermsAccepted: ${project.isTermsAccepted},
|
|
|
|
}
|
|
|
|
) {id}
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
2018-11-28 09:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for fetching all projects of current user.
|
|
|
|
export async function fetchProjects(): Promise<any> {
|
2018-12-20 16:18:08 +00:00
|
|
|
let response: any = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await apollo.query(
|
|
|
|
{
|
|
|
|
query: gql(`
|
|
|
|
query {
|
|
|
|
myProjects{
|
|
|
|
name
|
|
|
|
id
|
|
|
|
description
|
|
|
|
createdAt
|
|
|
|
isTermsAccepted
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2018-12-18 14:43:23 +00:00
|
|
|
}
|
2018-11-28 09:43:43 +00:00
|
|
|
|
2018-12-20 16:18:08 +00:00
|
|
|
return response;
|
2018-11-28 09:43:43 +00:00
|
|
|
}
|
2018-11-28 16:20:23 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request for updating selected project description
|
|
|
|
export async function updateProject(projectID: string, description: string): Promise<any> {
|
2018-12-20 16:18:08 +00:00
|
|
|
let response: any = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
updateProjectDescription(
|
|
|
|
id: "${projectID}",
|
|
|
|
description: "${description}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
2018-11-28 16:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for deleting selected project
|
|
|
|
export async function deleteProject(projectID: string): Promise<any> {
|
2018-12-20 16:18:08 +00:00
|
|
|
let response: any = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
deleteProject(
|
|
|
|
id: "${projectID}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
2018-11-28 16:20:23 +00:00
|
|
|
}
|