]>
Commit | Line | Data |
---|---|---|
a6a79eae C |
1 | import { HttpStatusCode } from '@shared/core-utils' |
2 | import { makePostBodyRequest } from '../requests/requests' | |
3 | import { ServerInfo } from '../server/servers' | |
4 | ||
5 | export interface CommonCommandOptions { | |
6 | token?: string | |
7 | expectedStatus?: number | |
8 | } | |
9 | ||
10 | abstract class AbstractCommand { | |
11 | ||
12 | private expectedStatus = HttpStatusCode.OK_200 | |
13 | ||
14 | constructor ( | |
15 | protected server: ServerInfo | |
16 | ) { | |
17 | ||
18 | } | |
19 | ||
20 | setServer (server: ServerInfo) { | |
21 | this.server = server | |
22 | } | |
23 | ||
24 | setExpectedStatus (status: HttpStatusCode) { | |
25 | this.expectedStatus = status | |
26 | } | |
27 | ||
28 | protected postBodyRequest (options: CommonCommandOptions & { | |
29 | path: string | |
30 | defaultExpectedStatus: number | |
31 | fields?: { [ fieldName: string ]: any } | |
32 | }) { | |
33 | const { token, fields, expectedStatus, defaultExpectedStatus, path } = options | |
34 | ||
35 | return makePostBodyRequest({ | |
36 | url: this.server.url, | |
37 | path, | |
38 | token: token ?? this.server.accessToken, | |
39 | fields, | |
40 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus | |
41 | }) | |
42 | } | |
43 | } | |
44 | ||
45 | export { | |
46 | AbstractCommand | |
47 | } |