From 519de436349b44f9d3116284fb3258c7b7f022a6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 Jul 2023 16:13:22 +0200 Subject: [PATCH] Bug 34219: Allow getAll to receive additional URL parameters It's not possible to pass additional URL parameters. We need it at least for bug 32474. Signed-off-by: Pedro Amorim Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f1078daf8f496e1b4234acf766578c511ca8aad1) Signed-off-by: Fridolin Somers (cherry picked from commit 6f9dd5e449a5458966d373532fe9eeade82670b1) Signed-off-by: Matt Blenkinsop --- .../js/vue/fetch/acquisition-api-client.js | 9 ++- .../prog/js/vue/fetch/erm-api-client.js | 15 +++-- .../prog/js/vue/fetch/http-client.js | 64 ++++++++++++------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js index 4353ef0ad4..d3f4e5ddd2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js @@ -9,9 +9,14 @@ export class AcquisitionAPIClient extends HttpClient { get vendors() { return { - getAll: (query) => + getAll: (query, params) => this.get({ - endpoint: "vendors?" + (query || "_per_page=-1"), + endpoint: "vendors", + query, + params, + headers: { + "x-koha-embed": "aliases", + }, }), }; } 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 f9be2c5aa0..e298f7f8fb 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 @@ -17,10 +17,11 @@ export class ERMAPIClient extends HttpClient { "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents,agreement_packages,agreement_packages.package,vendor", }, }), - getAll: query => + getAll: (query, params) => this.getAll({ endpoint: "agreements", - query: query, + query, + params, }), delete: id => this.delete({ @@ -59,10 +60,11 @@ export class ERMAPIClient extends HttpClient { "user_roles,user_roles.patron,vendor,documents", }, }), - getAll: query => + getAll: (query, params) => this.getAll({ endpoint: "licenses", - query: query, + query, + params, headers: { "x-koha-embed": "vendor", }, @@ -104,10 +106,11 @@ export class ERMAPIClient extends HttpClient { "package_agreements,package_agreements.agreement,resources+count,vendor", }, }), - getAll: query => + getAll: (query, params) => this.getAll({ endpoint: "eholdings/local/packages", - query: query, + query, + params, headers: { "x-koha-embed": "resources+count,vendor.name", }, 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 fda106b9e1..8d880d258e 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 @@ -13,30 +13,31 @@ class HttpClient { headers = {}, options = {}, return_response = false, - mark_submitting = false, + mark_submitting = false ) { let res, error; - if ( mark_submitting) submitting() + if (mark_submitting) submitting(); await fetch(this._baseURL + endpoint, { ...options, headers: { ...this._headers, ...headers }, }) - .then((response) => this.checkError(response, return_response)) + .then(response => this.checkError(response, return_response)) .then( - (result) => { + result => { res = result; }, - (err) => { + err => { error = err; setError(err.toString()); } ) - .catch((err) => { + .catch(err => { error = err; setError(err); - }).then(() => { - if (mark_submitting) submitted()}) - ; + }) + .then(() => { + if (mark_submitting) submitted(); + }); if (error) throw Error(error); @@ -52,11 +53,13 @@ class HttpClient { getAll(params = {}) { let url = - params.endpoint + "?" + + params.endpoint + + "?" + new URLSearchParams({ _per_page: -1, + ...(params.params && params.params), ...(params.query && { q: JSON.stringify(params.query) }), - }) + }); return this._fetchJSON(url, params.headers, { ...params.options, method: "GET", @@ -69,11 +72,17 @@ class HttpClient { ? params.body : JSON.stringify(params.body) : undefined; - return this._fetchJSON(params.endpoint, params.headers, { - ...params.options, - body, - method: "POST", - }, false, true); + return this._fetchJSON( + params.endpoint, + params.headers, + { + ...params.options, + body, + method: "POST", + }, + false, + true + ); } put(params = {}) { @@ -82,11 +91,17 @@ class HttpClient { ? params.body : JSON.stringify(params.body) : undefined; - return this._fetchJSON(params.endpoint, params.headers, { - ...params.options, - body, - method: "PUT", - }, false, true); + return this._fetchJSON( + params.endpoint, + params.headers, + { + ...params.options, + body, + method: "PUT", + }, + false, + true + ); } delete(params = {}) { @@ -98,19 +113,20 @@ class HttpClient { ...params.options, method: "DELETE", }, - true, true + true, + true ); } count(params = {}) { let res; return this._fetchJSON(params.endpoint, params.headers, {}, 1).then( - (response) => { + response => { if (response) { return response.headers.get("X-Total-Count"); } }, - (error) => { + error => { setError(error.toString()); } ); -- 2.39.5