-
Notifications
You must be signed in to change notification settings - Fork 5
/
API.ts
38 lines (33 loc) · 1.01 KB
/
API.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import axios from "axios";
import { AccessStatus, Project } from "../types";
export default class API {
owner?: string;
title?: string;
constructor(owner, title) {
this.owner = owner;
this.title = title;
}
async getAccessStatus(): Promise<AccessStatus> {
if (this.owner && this.title) {
return (await axios.get(`/users/status/${this.owner}/${this.title}/`)).data;
} else {
return (await axios.get(`/users/status/`)).data;
}
}
async getProject(): Promise<Project> {
return (await axios.get(`/apps/api/v1/${this.owner}/${this.title}/`)).data;
}
async updateProject(data): Promise<Project> {
return (await axios.put(`/apps/api/v1/${this.owner}/${this.title}/`, data)).data;
}
async createProject(data): Promise<Project> {
return (await axios.post(`/apps/api/v1/`, data)).data;
}
async save(data): Promise<Project> {
if (this.owner && this.title) {
return await this.updateProject(data);
} else {
return await this.createProject(data);
}
}
}