-
Notifications
You must be signed in to change notification settings - Fork 0
/
rig.ts
53 lines (42 loc) · 1.64 KB
/
rig.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
EntityBase
} from '../brainstorm/app/models';
import { RigState } from './rig-state';
export class Rig {
protected readonly baseUrl: string;
protected get = async (endpoint: string): Promise<any> => (
await fetch(endpoint, {
credentials: 'include'
})
).json();
protected post = async (endpoint: string, data: string): Promise<any> => (
await fetch(endpoint, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
credentials: 'include',
body: data
})
).json();
constructor(
protected url: string = `http://localhost:5001/api/rig/`
) {
this.baseUrl = url ?? `http://localhost:5001/api/rig/`;
}
getState = async (): Promise<RigState> =>
await this.get(`${this.baseUrl}getState`);
initializeDatabase = async (): Promise<RigState> =>
await this.get(`${this.baseUrl}initializeDatabase`);
destroyDatabase = async (): Promise<RigState> =>
await this.get(`${this.baseUrl}destroyDatabase`);
startProcess = async (): Promise<RigState> =>
await this.get(`${this.baseUrl}startProcess`);
killProcess = async (): Promise<RigState> =>
await this.get(`${this.baseUrl}killProcess`);
seed = async <T extends EntityBase>(entity: T, endpoint: string) =>
this.post(`${this.baseUrl}${endpoint}`, JSON.stringify(entity));
seedMany = async <T extends EntityBase>(entities: T[], endpoint: string) =>
this.post(`${this.baseUrl}${endpoint}`, JSON.stringify(entities));
}