2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-28 09:43:43 +00:00
|
|
|
// 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.
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function createProjectRequest(project: Project): Promise<RequestResponse<Project>> {
|
2018-12-24 12:52:52 +00:00
|
|
|
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}",
|
|
|
|
}
|
|
|
|
) {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.
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function fetchProjectsRequest(): Promise<RequestResponse<Project[]>> {
|
2018-12-24 12:52:52 +00:00
|
|
|
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
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function updateProjectRequest(projectID: string, description: string): Promise<RequestResponse<null>> {
|
2018-12-24 12:52:52 +00:00
|
|
|
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}"
|
2019-01-11 10:08:51 +00:00
|
|
|
) {name}
|
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;
|
|
|
|
}
|
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
|
2019-01-08 15:14:00 +00:00
|
|
|
export async function deleteProjectRequest(projectID: string): Promise<RequestResponse<null>> {
|
2018-12-24 12:52:52 +00:00
|
|
|
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}"
|
2019-01-11 10:08:51 +00:00
|
|
|
) {name}
|
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;
|
|
|
|
}
|
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
|
|
|
}
|