From 40aebe30a1ccc96aa7e086f68ee8c22e8c3eea3a Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:09:32 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20function=20=E0=B8=95=E0=B9=88=E0=B8=AD=20=20api=20P?= =?UTF-8?q?roduct=20Group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/product-service/index.ts | 109 +++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index a7ec3b51..59deabeb 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -1,5 +1,112 @@ import { defineStore } from 'pinia'; +import { api } from 'src/boot/axios'; +import { ProductGroup, ProductGroupCreate, ProductGroupUpdate } from './types'; const useProductServiceStore = defineStore('api-product-service', () => { - return {}; + async function fetchStatsProductGroup() { + const res = await api.get('/product-group/stats'); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + + async function fetchListProductServiceById(groupId: string) { + const res = await api.get(`/product-group/${groupId}`); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + + async function fetchListProductService( + opts?: { query?: string }, + flow?: { + sessionId: string; + refTransactionId: string; + transactionId: string; + }, + ) { + const params = new URLSearchParams(); + + for (const [k, v] of Object.entries(opts || {})) { + v !== undefined && params.append(k, v.toString()); + } + + const query = params.toString(); + + const res = await api.get( + `/product-group${(params && '?'.concat(query)) || ''}`, + { + headers: { + 'X-Session-Id': flow?.sessionId, + 'X-Rtid': flow?.refTransactionId, + 'X-Tid': flow?.transactionId, + }, + }, + ); + + if (!res) return false; + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function createProductService() { + const res = await api.post('/product-group'); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function editProductService( + groupId: string, + opts: { data: ProductGroupUpdate }, + ) { + const res = await api.put(`/product-group/${groupId}`, { + ...opts.data, + }); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function deleteProductService(groupId: string) { + const res = await api.delete(`/product-group/${groupId}`); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + return { + fetchStatsProductGroup, + fetchListProductServiceById, + fetchListProductService, + createProductService, + editProductService, + deleteProductService, + }; }); + +export default useProductServiceStore;