From c9d6cf4b7d9f9330dcd135b78d7ede87307bc9d9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Feb 2023 10:43:46 +0100 Subject: [PATCH] Bug 32939: Introduce count Not used yet, will replace myFetchTotal --- .../prog/js/vue/fetch/http-client.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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 d1b5a917b9e..3f1133d69d3 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 @@ -8,13 +8,13 @@ class HttpClient { }; } - async _fetchJSON(endpoint, headers = {}, options = {}) { + async _fetchJSON(endpoint, headers = {}, options = {}, return_response = false) { let res; await fetch(this._baseURL + endpoint, { ...options, headers: { ...this._headers, ...headers }, }) - .then(this.checkError) + .then((response) => this.checkError(response, return_response)) .then( (result) => { res = result; @@ -60,6 +60,21 @@ class HttpClient { }); } + count(params = {}) { + let res; + this._fetchJSON(params.endpoint, params.headers, 1).then( + (response) => { + if (response) { + res = response.headers.get("X-Total-Count"); + } + }, + (error) => { + setError(error.toString()); + } + ); + return res; + } + checkError(response, return_response = 0) { if (response.status >= 200 && response.status <= 299) { return return_response ? response : response.json(); @@ -70,7 +85,6 @@ class HttpClient { } } - //TODO: Implement count method } export default HttpClient; -- 2.25.1