From 3bf8ac3be8e0f1d6739aeccae849aff700b491c4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Feb 2023 10:13:58 +0100 Subject: [PATCH] Bug 32939: Set the default header at lower level --- .../intranet-tmpl/prog/js/vue/fetch/erm-api-client.js | 5 +---- .../intranet-tmpl/prog/js/vue/fetch/http-client.js | 10 ++++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js index bdad9f6b179..e16e35b2b55 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js @@ -24,23 +24,20 @@ export class ERMAPIClient extends HttpClient { delete: (id) => this.delete({ endpoint: "agreements/" + id, - headers: this.getDefaultJSONPayloadHeader(), }), create: (agreement) => this.post({ endpoint: "agreements", body: agreement, - headers: this.getDefaultJSONPayloadHeader(), }), update: (agreement, id) => this.put({ endpoint: "agreements/" + id, body: agreement, - headers: this.getDefaultJSONPayloadHeader(), }), //count: () => this.count("agreements"), //TODO: Implement count method }; } } -export default ERMAPIClient; \ No newline at end of file +export default ERMAPIClient; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js index 6a47276dcf2..63731a5657a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js @@ -1,12 +1,15 @@ class HttpClient { constructor(options = {}) { this._baseURL = options.baseURL || ""; + this._headers = options.headers || { + "Content-Type": "application/json;charset=utf-8", + }; } async _fetchJSON(endpoint, headers = {}, options = {}) { const res = await fetch(this._baseURL + endpoint, { ...options, - headers: headers, + headers: { ...this._headers, ...headers }, }); if (!res.ok) throw new Error(res.statusText); @@ -18,7 +21,6 @@ class HttpClient { } get(params = {}) { - console.log(params); return this._fetchJSON(params.endpoint, params.headers, { ...params.options, method: "GET", @@ -50,10 +52,6 @@ class HttpClient { } //TODO: Implement count method - - getDefaultJSONPayloadHeader() { - return { "Content-Type": "application/json;charset=utf-8" }; - } } export default HttpClient; -- 2.25.1