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
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
// Performs graqhQL request for project creation.
|
|
|
|
export async function createProject(project: Project): Promise<RequestResponse<Project>> {
|
|
|
|
let result: RequestResponse<Project> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: project
|
|
|
|
};
|
2018-12-20 16:18:08 +00:00
|
|
|
|
|
|
|
try {
|
2018-12-24 12:52:52 +00:00
|
|
|
let response: any = await apollo.mutate(
|
2018-12-20 16:18:08 +00:00
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
createProject(
|
|
|
|
input: {
|
|
|
|
name: "${project.name}",
|
|
|
|
description: "${project.description}",
|
|
|
|
isTermsAccepted: ${project.isTermsAccepted},
|
|
|
|
}
|
|
|
|
) {id}
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
2018-12-24 12:52:52 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
result.data.id = response.data.createProject.id;
|
|
|
|
}
|
2018-12-20 16:18:08 +00:00
|
|
|
} catch (e) {
|
2018-12-24 12:52:52 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-20 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return result;
|
2018-11-28 09:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for fetching all projects of current user.
|
2018-12-24 12:52:52 +00:00
|
|
|
export async function fetchProjects(): Promise<RequestResponse<Project[]>> {
|
|
|
|
let result: RequestResponse<Project[]> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: []
|
|
|
|
};
|
2018-12-20 16:18:08 +00:00
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
try {
|
|
|
|
let response: any = await apollo.query(
|
2018-12-20 16:18:08 +00:00
|
|
|
{
|
|
|
|
query: gql(`
|
|
|
|
query {
|
|
|
|
myProjects{
|
|
|
|
name
|
|
|
|
id
|
|
|
|
description
|
2018-12-24 12:52:52 +00:00
|
|
|
createdAt
|
2018-12-20 16:18:08 +00:00
|
|
|
}
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
result.data = response.data.myProjects;
|
|
|
|
}
|
2018-12-20 16:18:08 +00:00
|
|
|
} catch (e) {
|
2018-12-24 12:52:52 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-18 14:43:23 +00:00
|
|
|
}
|
2018-11-28 09:43:43 +00:00
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return result;
|
2018-11-28 09:43:43 +00:00
|
|
|
}
|
2018-11-28 16:20:23 +00:00
|
|
|
|
|
|
|
// Performs graqhQL request for updating selected project description
|
2018-12-24 12:52:52 +00:00
|
|
|
export async function updateProject(projectID: string, description: string): Promise<RequestResponse<null>> {
|
|
|
|
let result: RequestResponse<null> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
|
|
|
};
|
2018-12-20 16:18:08 +00:00
|
|
|
|
|
|
|
try {
|
2018-12-24 12:52:52 +00:00
|
|
|
let response: any = await apollo.mutate(
|
2018-12-20 16:18:08 +00:00
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
updateProjectDescription(
|
|
|
|
id: "${projectID}",
|
|
|
|
description: "${description}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
2018-12-24 12:52:52 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
}
|
2018-12-20 16:18:08 +00:00
|
|
|
} catch (e) {
|
2018-12-24 12:52:52 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-20 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return result;
|
2018-11-28 16:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Performs graqhQL request for deleting selected project
|
2018-12-24 12:52:52 +00:00
|
|
|
export async function deleteProject(projectID: string): Promise<RequestResponse<null>> {
|
|
|
|
let result: RequestResponse<null> = {
|
|
|
|
errorMessage: '',
|
|
|
|
isSuccess: false,
|
|
|
|
data: null
|
|
|
|
};
|
2018-12-20 16:18:08 +00:00
|
|
|
|
|
|
|
try {
|
2018-12-24 12:52:52 +00:00
|
|
|
let response = await apollo.mutate(
|
2018-12-20 16:18:08 +00:00
|
|
|
{
|
|
|
|
mutation: gql(`
|
|
|
|
mutation {
|
|
|
|
deleteProject(
|
|
|
|
id: "${projectID}"
|
|
|
|
)
|
|
|
|
}`
|
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
}
|
|
|
|
);
|
2018-12-24 12:52:52 +00:00
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
}
|
2018-12-20 16:18:08 +00:00
|
|
|
} catch (e) {
|
2018-12-24 12:52:52 +00:00
|
|
|
result.errorMessage = e.message;
|
2018-12-20 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
return result;
|
2018-11-28 16:20:23 +00:00
|
|
|
}
|