From 0bc415802e7ec18ae4a2de52b88c00e354f09383 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 21 Feb 2023 10:50:02 +0100 Subject: [PATCH] Bug 32939: Use APIClient to fetch vendors --- .../prog/js/vue/components/ERM/Main.vue | 11 ++++++++-- .../js/vue/fetch/acquisition-api-client.js | 20 +++++++++++++++++++ .../prog/js/vue/fetch/api-client.js | 2 ++ .../intranet-tmpl/prog/js/vue/fetch/erm.js | 5 ----- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue index f9f949a6356..5eba5d1ee8d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue @@ -122,7 +122,7 @@ import { inject } from "vue" import Breadcrumb from "../../components/Breadcrumb.vue" import Dialog from "../../components/Dialog.vue" -import { fetchVendors } from "../../fetch/erm.js" +import { APIClient } from "../../fetch/api-client.js" import "vue-select/dist/vue-select.css" export default { @@ -154,7 +154,14 @@ export default { } }, beforeCreate() { - fetchVendors().then(vendors => (this.vendorStore.vendors = vendors)) + const client = APIClient.acquisition + client.vendors.getAll().then( + vendors => { + this.vendors = vendors + this.initialized = true + }, + error => {} + ) }, components: { Breadcrumb, 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 new file mode 100644 index 00000000000..4353ef0ad40 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js @@ -0,0 +1,20 @@ +import HttpClient from "./http-client"; + +export class AcquisitionAPIClient extends HttpClient { + constructor() { + super({ + baseURL: "/api/v1/acquisitions/", + }); + } + + get vendors() { + return { + getAll: (query) => + this.get({ + endpoint: "vendors?" + (query || "_per_page=-1"), + }), + }; + } +} + +export default AcquisitionAPIClient; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js index 0b11b7f6d05..20ceaa2e40d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js @@ -1,7 +1,9 @@ import ERMAPIClient from "./erm-api-client"; import PatronAPIClient from "./patron-api-client"; +import AcquisitionAPIClient from "./acquisition-api-client"; export const APIClient = { erm: new ERMAPIClient(), patron: new PatronAPIClient(), + acquisition: new AcquisitionAPIClient(), }; \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js index 9d8a2459339..b76ce379d9f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js @@ -2,11 +2,6 @@ import { setError } from "../messages"; //TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient -export const fetchVendors = function () { - const apiUrl = "/api/v1/acquisitions/vendors?_per_page=-1"; - return myFetch(apiUrl); -}; - const _createEditPackage = function (method, erm_package) { let apiUrl = "/api/v1/erm/eholdings/local/packages"; -- 2.25.1