diff options
author | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-12-11 01:37:15 +0300 |
---|---|---|
committer | Marius David Wieschollek <passwords.public@mdns.eu> | 2020-12-11 01:37:15 +0300 |
commit | b31a64bd2a22becee5bc2e49c32c3028491899f4 (patch) | |
tree | a00e7686cb09979d6892d98da8341a9acb50909e /src | |
parent | 277f5a1571a1a839d4f000a8ef65e35cba5b05ce (diff) |
Fix update function
Signed-off-by: Marius David Wieschollek <passwords.public@mdns.eu>
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/ApiRequest.js | 17 | ||||
-rw-r--r-- | src/Repositories/AbstractRepository.js | 3 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/Network/ApiRequest.js b/src/Network/ApiRequest.js index 9a6af72..0be8cc8 100644 --- a/src/Network/ApiRequest.js +++ b/src/Network/ApiRequest.js @@ -13,6 +13,7 @@ export default class ApiRequest { this._url = url; this._path = null; this._data = null; + this._method = null; this._userAgent = null; this._session = session; this._responseType = 'application/json'; @@ -82,6 +83,17 @@ export default class ApiRequest { * @param {String} value * @return {ApiRequest} */ + setMethod(value) { + this._method = value.toUpperCase(); + + return this; + } + + /** + * + * @param {String} value + * @return {ApiRequest} + */ setUserAgent(value) { this._userAgent = value; @@ -128,13 +140,12 @@ export default class ApiRequest { */ _getRequestOptions() { let headers = this._getRequestHeaders(); - let method = 'GET'; + let method = this._method === null ? 'GET':this._method; let options = {method, headers, credentials: 'omit', redirect: 'error'}; if(this._data !== null) { options.body = JSON.stringify(this._data); - method = 'POST'; + if(method === 'GET') options.method = 'POST'; } - options.method = method; return options; } diff --git a/src/Repositories/AbstractRepository.js b/src/Repositories/AbstractRepository.js index ee2cf29..9c03566 100644 --- a/src/Repositories/AbstractRepository.js +++ b/src/Repositories/AbstractRepository.js @@ -85,8 +85,9 @@ export default class AbstractRepository { throw new Error('Can not update object without id'); } - let data = this._converter.toApiObject(model), + let data = await this._converter.toApiObject(model), request = this._api.getRequest() + .setMethod('PATCH') .setPath(`1.0/${this.TYPE}/update`) .setData(data); |