From b7feb64619e9b78cfc1f4f739790d7d264e4af2f Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 28 Apr 2023 10:23:35 +0000 Subject: [PATCH] Bug 33623: Move ULSearchParams into http-client.js Remove unused getAll methods in erm-api-client.js Make use of new getAll query in AgreementRelationships Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- .../components/ERM/AgreementRelationships.vue | 18 +++--- .../prog/js/vue/fetch/erm-api-client.js | 63 +++---------------- .../prog/js/vue/fetch/http-client.js | 13 ++++ 3 files changed, 31 insertions(+), 63 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue index 0465bb867e..5cf3a23314 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementRelationships.vue @@ -99,15 +99,15 @@ export default { }, beforeCreate() { const client = APIClient.erm - client.agreements.getAll().then( - agreements => { - this.agreements = agreements.filter( - agreement => agreement.agreement_id !== this.agreement_id - ) - this.initialized = true - }, - error => {} - ) + client.agreements + .getAll({ "me.agreement_id": { "!=": this.agreement_id } }) + .then( + agreements => { + this.agreements = agreements + this.initialized = true + }, + error => {} + ) }, methods: { addRelationship() { 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 d28320f176..f9be2c5aa0 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 @@ -18,13 +18,9 @@ export class ERMAPIClient extends HttpClient { }, }), getAll: query => - this.get({ - endpoint: - "agreements?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), + this.getAll({ + endpoint: "agreements", + query: query, }), delete: id => this.delete({ @@ -64,13 +60,9 @@ export class ERMAPIClient extends HttpClient { }, }), getAll: query => - this.get({ - endpoint: - "licenses?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), + this.getAll({ + endpoint: "licenses", + query: query, headers: { "x-koha-embed": "vendor", }, @@ -113,13 +105,9 @@ export class ERMAPIClient extends HttpClient { }, }), getAll: query => - this.get({ - endpoint: - "eholdings/local/packages?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), + this.getAll({ + endpoint: "eholdings/local/packages", + query: query, headers: { "x-koha-embed": "resources+count,vendor.name", }, @@ -160,15 +148,6 @@ export class ERMAPIClient extends HttpClient { "x-koha-embed": "resources,resources.package", }, }), - getAll: query => - this.get({ - endpoint: - "eholdings/local/titles?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), - }), delete: id => this.delete({ endpoint: "eholdings/local/titles/" + id, @@ -223,20 +202,6 @@ export class ERMAPIClient extends HttpClient { "package_agreements,package_agreements.agreement,resources+count,vendor", }, }), - getAll: query => - this.get({ - endpoint: - "eholdings/ebsco/packages/" + - id + - "?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), - headers: { - "x-koha-embed": "resources+count,vendor.name", - }, - }), patch: (id, body) => this.patch({ endpoint: "eholdings/ebsco/packages/" + id, @@ -254,16 +219,6 @@ export class ERMAPIClient extends HttpClient { "x-koha-embed": "resources,resources.package", }, }), - getAll: query => - this.get({ - endpoint: - "eholdings/local/ebsco/titles" + - "?" + - new URLSearchParams({ - _per_page: -1, - ...(query && { q: JSON.stringify(query) }), - }), - }), }; } 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 ac999e9f9a..fda106b9e1 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 @@ -50,6 +50,19 @@ class HttpClient { }); } + getAll(params = {}) { + let url = + params.endpoint + "?" + + new URLSearchParams({ + _per_page: -1, + ...(params.query && { q: JSON.stringify(params.query) }), + }) + return this._fetchJSON(url, params.headers, { + ...params.options, + method: "GET", + }); + } + post(params = {}) { const body = params.body ? typeof params.body === "string" -- 2.39.5