2018-11-28 09:43:43 +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 createProject(project: Project): Promise<any> {
|
2018-12-06 15:19:47 +00:00
|
|
|
console.log("in api", project);
|
|
|
|
|
2018-11-28 09:43:43 +00:00
|
|
|
let response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
createProject(
|
|
|
|
input: {
|
|
|
|
name: "${project.name}",
|
|
|
|
description: "${project.description}",
|
2018-12-06 15:19:47 +00:00
|
|
|
companyName: "${project.companyName}",
|
2018-11-28 09:43:43 +00:00
|
|
|
isTermsAccepted: ${project.isTermsAccepted},
|
|
|
|
}
|
2018-12-10 12:29:01 +00:00
|
|
|
) {id}
|
2018-11-28 09:43:43 +00:00
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!response){
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.log("cannot create project");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for fetching all projects of current user.
|
|
|
|
export async function fetchProjects(): Promise<any> {
|
|
|
|
let response = await apollo.query(
|
|
|
|
{
|
|
|
|
query: gql(`
|
|
|
|
query {
|
|
|
|
myProjects{
|
|
|
|
name
|
|
|
|
id
|
2018-11-28 16:20:23 +00:00
|
|
|
description
|
|
|
|
createdAt
|
|
|
|
ownerName
|
2018-12-06 15:19:47 +00:00
|
|
|
companyName
|
2018-11-28 16:20:23 +00:00
|
|
|
isTermsAccepted
|
2018-11-28 09:43:43 +00:00
|
|
|
}
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!response){
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.log("cannot fetch projects");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
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> {
|
|
|
|
let response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
updateProjectDescription(
|
|
|
|
id: "${projectID}",
|
|
|
|
description: "${description}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!response){
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.log("cannot update project");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for deleting selected project
|
|
|
|
export async function deleteProject(projectID: string): Promise<any> {
|
|
|
|
let response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
deleteProject(
|
|
|
|
id: "${projectID}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: "no-cache",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!response){
|
|
|
|
// TODO: replace with popup in future
|
|
|
|
console.log("cannot delete project");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|