From 4ffe9a6ed99c463d7126b920ff9a026cd68195f4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 25 Apr 2023 12:11:51 +0200 Subject: [PATCH] Bug 34055: Add API client class to get items This patch add a new item-api-client.js API client to fetch items using our /items REST API endpoint. Test plan: Add the following two lines to one of the existing Vue component (in data() for instance) and hit the view that is using it. let client = APIClient.item client.items.getAll().then((items) => console.log(items)) Notice that you see all the items in the console. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Matt Blenkinsop Was failing the pretty test, fixed with yarn pretty Signed-off-by: Chris Cormack Signed-off-by: Tomas Cohen Arazi --- .../prog/js/vue/fetch/api-client.js | 2 ++ .../prog/js/vue/fetch/item-api-client.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/fetch/item-api-client.js 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 6ac1717fbf..e570309fa1 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 @@ -2,6 +2,7 @@ import ERMAPIClient from "./erm-api-client"; import PatronAPIClient from "./patron-api-client"; import AcquisitionAPIClient from "./acquisition-api-client"; import AVAPIClient from "./authorised-values-api-client"; +import ItemAPIClient from "./item-api-client"; import SysprefAPIClient from "./system-preferences-api-client"; export const APIClient = { @@ -9,5 +10,6 @@ export const APIClient = { patron: new PatronAPIClient(), acquisition: new AcquisitionAPIClient(), authorised_values: new AVAPIClient(), + item: new ItemAPIClient(), sysprefs: new SysprefAPIClient(), }; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/item-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/item-api-client.js new file mode 100644 index 0000000000..87df66c29a --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/item-api-client.js @@ -0,0 +1,26 @@ +import HttpClient from "./http-client"; + +export class ItemAPIClient extends HttpClient { + constructor() { + super({ + baseURL: "/api/v1/", + }); + } + + get items() { + return { + getAll: (query, params) => + this.get({ + endpoint: + "items?" + + new URLSearchParams({ + _per_page: -1, + ...(query && { q: JSON.stringify(query) }), + }), + ...params, + }), + }; + } +} + +export default ItemAPIClient; -- 2.39.5