Bugzilla – Attachment 147073 Details for
Bug 32939
Have generic fetch functions in vue modules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32939: Use APIClient to replace PATCH requests
Bug-32939-Use-APIClient-to-replace-PATCH-requests.patch (text/plain), 9.33 KB, created by
Matt Blenkinsop
on 2023-02-21 16:16:01 UTC
(
hide
)
Description:
Bug 32939: Use APIClient to replace PATCH requests
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-02-21 16:16:01 UTC
Size:
9.33 KB
patch
obsolete
>From 1718775c2fc55373ab8bdd33ade65483e358ed1d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 21 Feb 2023 13:09:23 +0100 >Subject: [PATCH] Bug 32939: Use APIClient to replace PATCH requests > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > .../ERM/EHoldingsEBSCOPackagesShow.vue | 26 ++++-------- > .../ERM/EHoldingsEBSCOResourcesShow.vue | 27 ++++-------- > .../ERM/EHoldingsLocalTitlesFormImport.vue | 16 ++----- > .../prog/js/vue/fetch/erm-api-client.js | 16 ++++++- > .../prog/js/vue/fetch/http-client.js | 42 +++++++++++++++---- > 5 files changed, 70 insertions(+), 57 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesShow.vue >index abb80afccc3..a90b0d1523f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesShow.vue >@@ -170,26 +170,16 @@ export default { > }, > edit_selected(is_selected) { > this.updating_is_selected = true >- fetch( >- "/api/v1/erm/eholdings/ebsco/packages/" + >- this.erm_package.package_id, >- { >- method: "PATCH", >- body: JSON.stringify({ is_selected }), >- headers: { >- Accept: "application/json", >- "Content-Type": "application/json", >- }, >- } >- ) >- .then(checkError) >- .then(result => { >+ const client = APIClient.erm >+ client.EBSCOPackages.patch(this.erm_package.package_id, { >+ is_selected, >+ }).then( >+ result => { > // Refresh the page. We should not need that actually. > this.getPackage(this.erm_package.package_id) >- }) >- .catch(error => { >- setError(error) >- }) >+ }, >+ error => {} >+ ) > }, > add_to_holdings() { > this.edit_selected(true) >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOResourcesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOResourcesShow.vue >index e764194e937..68d5e23e310 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOResourcesShow.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOResourcesShow.vue >@@ -116,7 +116,6 @@ > <script> > import { inject } from "vue" > import { storeToRefs } from "pinia" >-import { checkError } from "../../fetch/erm.js" > import { APIClient } from "../../fetch/api-client.js" > > export default { >@@ -169,26 +168,16 @@ export default { > }, > edit_selected(is_selected) { > this.updating_is_selected = true >- fetch( >- "/api/v1/erm/eholdings/ebsco/resources/" + >- this.resource.resource_id, >- { >- method: "PATCH", >- body: JSON.stringify({ is_selected }), >- headers: { >- Accept: "application/json", >- "Content-Type": "application/json", >- }, >- } >- ) >- .then(checkError) >- .then(result => { >+ const client = APIClient.erm >+ client.EBSCOResources.patch(this.resource.resource_id, { >+ is_selected, >+ }).then( >+ result => { > // Refresh the page. We should not need that actually. > this.getResource(this.resource.resource_id) >- }) >- .catch(error => { >- setError(error) >- }) >+ }, >+ error => {} >+ ) > }, > add_to_holdings() { > this.edit_selected(true) >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >index 04c9089e4c1..fc3133b61cc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue >@@ -65,22 +65,14 @@ export default { > return > } > if (!list_id) return >- await fetch("/api/v1/erm/eholdings/local/titles/import", { >- method: "POST", >- body: JSON.stringify({ list_id, package_id: this.package_id }), >- headers: { >- Accept: "application/json", >- "Content-Type": "application/json", >- }, >- }) >- .then(checkError) >+ const client = APIClient.erm >+ client.localTitles >+ .import({ list_id, package_id: this.package_id }) > .then( > result => { > this.job_id = result.job_id > }, >- error => { >- setError(error) >- } >+ error => {} > ) > }, > build_datatable: function () { >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 18cdf4b2751..8dbd9e5453a 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 >@@ -155,6 +155,11 @@ export class ERMAPIClient extends HttpClient { > ...(query && { q: JSON.stringify(query) }), > }), > }), >+ import: (body) => >+ this.post({ >+ endpoint: "eholdings/local/titles/import", >+ body, >+ }), > }; > } > >@@ -170,7 +175,6 @@ export class ERMAPIClient extends HttpClient { > }; > } > >- > get EBSCOPackages() { > return { > get: (id) => >@@ -191,6 +195,11 @@ export class ERMAPIClient extends HttpClient { > "x-koha-embed": "resources+count,vendor.name", > }, > }), >+ patch: (id, body) => >+ this.patch({ >+ endpoint: "eholdings/ebsco/packages/" + id, >+ body, >+ }), > }; > } > >@@ -220,6 +229,11 @@ export class ERMAPIClient extends HttpClient { > "x-koha-embed": "title,package,vendor", > }, > }), >+ patch: (id, body) => >+ this.patch({ >+ endpoint: "eholdings/ebsco/packages/" + id, >+ body, >+ }), > }; > } > } >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 41a938cd777..b4e0890acaa 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 >@@ -47,27 +47,42 @@ class HttpClient { > } > > post(params = {}) { >+ const body = params.body >+ ? typeof str === "string" >+ ? params.body >+ : JSON.stringify(params.body) >+ : undefined; > return this._fetchJSON(params.endpoint, params.headers, { > ...params.options, >- body: params.body ? JSON.stringify(params.body) : undefined, >+ body, > method: "POST", > }); > } > > put(params = {}) { >+ const body = params.body >+ ? typeof str === "string" >+ ? params.body >+ : JSON.stringify(params.body) >+ : undefined; > return this._fetchJSON(params.endpoint, params.headers, { > ...params.options, >- body: params.body ? JSON.stringify(params.body) : undefined, >+ body, > method: "PUT", > }); > } > > delete(params = {}) { >- return this._fetchJSON(params.endpoint, params.headers, { >- parseResponse: false, >- ...params.options, >- method: "DELETE", >- }, true); >+ return this._fetchJSON( >+ params.endpoint, >+ params.headers, >+ { >+ parseResponse: false, >+ ...params.options, >+ method: "DELETE", >+ }, >+ true >+ ); > } > > count(params = {}) { >@@ -84,6 +99,19 @@ class HttpClient { > ); > } > >+ patch(params = {}) { >+ const body = params.body >+ ? typeof str === "string" >+ ? params.body >+ : JSON.stringify(params.body) >+ : undefined; >+ return this._fetchJSON(params.endpoint, params.headers, { >+ ...params.options, >+ body, >+ method: "PATCH", >+ }); >+ } >+ > checkError(response, return_response = 0) { > if (response.status >= 200 && response.status <= 299) { > return return_response ? response : response.json(); >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32939
:
146470
|
146509
|
146642
|
146644
|
146645
|
146668
|
146669
|
146670
|
146671
|
146672
|
146674
|
146675
|
146676
|
146677
|
146678
|
146679
|
146680
|
146681
|
146682
|
147029
|
147030
|
147031
|
147032
|
147033
|
147034
|
147035
|
147036
|
147037
|
147038
|
147039
|
147040
|
147041
|
147042
|
147043
|
147044
|
147056
|
147057
|
147059
|
147060
|
147061
|
147062
|
147063
|
147064
|
147065
|
147066
|
147067
|
147068
|
147069
|
147070
|
147071
|
147072
|
147073
|
147306
|
147307
|
147308
|
147309
|
147310
|
147311
|
147312
|
147313
|
147314
|
147315
|
147316
|
147317
|
147318
|
147319
|
147320
|
147321
|
147322
|
147332
|
149441