Bug 32939: Set the default header at lower level
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 15 Feb 2023 09:13:58 +0000 (10:13 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Feb 2023 14:13:09 +0000 (11:13 -0300)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js
koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js

index bdad9f6..e16e35b 100644 (file)
@@ -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;
index 6a47276..63731a5 100644 (file)
@@ -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;