Bug 32939: Use APIClient to fetch vendors
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 21 Feb 2023 09:50:02 +0000 (10:50 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Feb 2023 14:13:11 +0000 (11:13 -0300)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue
koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js [new file with mode: 0644]
koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js
koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js

index f9f949a..5eba5d1 100644 (file)
 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 (file)
index 0000000..4353ef0
--- /dev/null
@@ -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;
index 0b11b7f..20ceaa2 100644 (file)
@@ -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
index 9d8a245..b76ce37 100644 (file)
@@ -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";