Skip to content

Commit 16ca8d7

Browse files
authored
Merge pull request #156 from ivnnv/add-patch-method
Add PATCH method support to the api command
2 parents ea8191d + 3707d11 commit 16ca8d7

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/api/ApiManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class ApiManager {
3838

3939
callApi(
4040
path: string,
41-
method: 'GET' | 'POST' /*| 'POST_DATA' Not used */,
41+
method: 'GET' | 'POST' | 'PATCH' /*| 'POST_DATA' Not used */,
4242
data: any
4343
) {
4444
const http = this.http

src/api/HttpClient.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class HttpClient {
1111
readonly GET = 'GET'
1212
readonly POST = 'POST'
1313
readonly POST_DATA = 'POST_DATA'
14+
readonly PATCH = 'PATCH'
1415
isDestroyed = false
1516

1617
constructor(
@@ -47,7 +48,7 @@ export default class HttpClient {
4748
}
4849

4950
fetch(
50-
method: 'GET' | 'POST' | 'POST_DATA',
51+
method: 'GET' | 'POST' | 'POST_DATA' | 'PATCH',
5152
endpoint: string,
5253
variables: any
5354
) {
@@ -123,7 +124,7 @@ export default class HttpClient {
123124
}
124125

125126
fetchInternal(
126-
method: 'GET' | 'POST' | 'POST_DATA',
127+
method: 'GET' | 'POST' | 'POST_DATA' | 'PATCH',
127128
endpoint: string,
128129
variables: any
129130
) {
@@ -135,6 +136,10 @@ export default class HttpClient {
135136
return this.postReq(endpoint, variables, method)
136137
}
137138

139+
if (method === this.PATCH) {
140+
return this.patchReq(endpoint, variables)
141+
}
142+
138143
throw new Error('Unknown method: ' + method)
139144
}
140145

@@ -175,4 +180,16 @@ export default class HttpClient {
175180
return data
176181
})
177182
}
183+
184+
patchReq(endpoint: string, variables: any) {
185+
const self = this
186+
187+
return Request.patch(this.baseUrl + endpoint, {
188+
headers: self.createHeaders(),
189+
body: variables,
190+
json: true
191+
}).then(function (data) {
192+
return data
193+
})
194+
}
178195
}

src/utils/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CANCEL_STRING = '-- CANCEL --'
66
const SETUP_PORT = 3000
77
const MIN_CHARS_FOR_PASSWORD = 8
88
const BASE_API_PATH = '/api/v2'
9-
const API_METHODS = ['GET', 'POST']
9+
const API_METHODS = ['GET', 'POST', 'PATCH']
1010

1111
export default {
1212
ADMIN_DOMAIN,

0 commit comments

Comments
 (0)