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';
|
2019-07-18 14:39:39 +01:00
|
|
|
import { RequestResponse } from '@/types/response';
|
|
|
|
import { CreateProjectModel, Project } from '@/types/projects';
|
2018-11-28 09:43:43 +00:00
|
|
|
|
2018-12-24 12:52:52 +00:00
|
|
|
// Performs graqhQL request for project creation.
|
2019-07-09 14:51:33 +01:00
|
|
|
export async function createProjectRequest(createProjectModel: CreateProjectModel): Promise<RequestResponse<Project>> {
|
2019-07-18 14:39:39 +01:00
|
|
|
let result: RequestResponse<Project> = new RequestResponse<Project>();
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
mutation($name: String!, $description: String!) {
|
|
|
|
createProject(
|
|
|
|
input: {
|
|
|
|
name: $name,
|
|
|
|
description: $description,
|
|
|
|
}
|
|
|
|
) {id}
|
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
name: createProjectModel.name,
|
|
|
|
description: createProjectModel.description
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-24 12:52:52 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
result.data.id = response.data.createProject.id;
|
2019-07-18 14:39:39 +01:00
|
|
|
result.data.description = createProjectModel.description;
|
|
|
|
result.data.name = createProjectModel.name;
|
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[]>> {
|
2019-07-18 14:39:39 +01:00
|
|
|
let result: RequestResponse<Project[]> = new RequestResponse<Project[]>();
|
2018-12-20 16:18:08 +00:00
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.query(
|
|
|
|
{
|
|
|
|
query: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
query {
|
|
|
|
myProjects{
|
|
|
|
name
|
|
|
|
id
|
|
|
|
description
|
|
|
|
createdAt
|
|
|
|
}
|
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-24 12:52:52 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
|
|
|
result.data = response.data.myProjects;
|
2019-02-20 13:33:56 +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-08-05 16:43:52 +01:00
|
|
|
export async function updateProjectRequest(projectId: string, description: string): Promise<RequestResponse<null>> {
|
2019-07-18 14:39:39 +01:00
|
|
|
let result: RequestResponse<null> = new RequestResponse<null>();
|
2018-12-20 16:18:08 +00:00
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response: any = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
mutation($projectId: String!, $description: String!) {
|
|
|
|
updateProjectDescription(
|
|
|
|
id: $projectId,
|
|
|
|
description: $description
|
|
|
|
) {name}
|
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
projectId: projectId,
|
|
|
|
description: description
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-24 12:52:52 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
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-08-05 16:43:52 +01:00
|
|
|
export async function deleteProjectRequest(projectId: string): Promise<RequestResponse<null>> {
|
2019-07-18 14:39:39 +01:00
|
|
|
let result: RequestResponse<null> = new RequestResponse<null>();
|
2018-12-20 16:18:08 +00:00
|
|
|
|
2019-04-05 16:08:14 +01:00
|
|
|
let response = await apollo.mutate(
|
|
|
|
{
|
|
|
|
mutation: gql(`
|
2019-08-05 16:43:52 +01:00
|
|
|
mutation($projectId: String!) {
|
|
|
|
deleteProject(
|
|
|
|
id: $projectId
|
|
|
|
) {name}
|
|
|
|
}`
|
2019-04-05 16:08:14 +01:00
|
|
|
),
|
2019-08-05 16:43:52 +01:00
|
|
|
variables: {
|
|
|
|
projectId: projectId
|
|
|
|
},
|
2019-04-05 16:08:14 +01:00
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
errorPolicy: 'all',
|
2018-12-24 12:52:52 +00:00
|
|
|
}
|
2019-04-05 16:08:14 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (response.errors) {
|
|
|
|
result.errorMessage = response.errors[0].message;
|
|
|
|
} else {
|
|
|
|
result.isSuccess = true;
|
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
|
|
|
}
|