From b2fad573c5c673518070975def74a84656f55819 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:52:17 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20function=20=E0=B8=95=E0=B9=88=E0=B8=AD?= =?UTF-8?q?=20api=20=E0=B8=82=E0=B8=AD=E0=B8=87=20work(=20type=20=20?= =?UTF-8?q?=E0=B8=A2=E0=B8=B1=E0=B8=87=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=95?= =?UTF-8?q?=E0=B8=A3=E0=B8=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/product-service/index.ts | 166 +++++++++++++++++++++++++++- 1 file changed, 163 insertions(+), 3 deletions(-) diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 717f02d8..1966cf4f 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -368,7 +368,6 @@ const useProductServiceStore = defineStore('api-product-service', () => { return false; } - // // Service async function fetchStatsService() { @@ -427,7 +426,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { const res = await api.post( '/service', { - ...payload, + ...payload, }, ); @@ -500,7 +499,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { const res = await api.put( `/service/${serviceId}`, { - ...payload, + ...payload, }, ); @@ -533,6 +532,160 @@ const useProductServiceStore = defineStore('api-product-service', () => { return false; } + // work + async function fetchListWork( + opts?: { + query?: string; + page?: number; + pageSize?: number; + baseonly?: boolean; + }, + 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>( + `/work${(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 createWork(data: ServiceCreate) { + const { image, ...payload } = data; + + const res = await api.post( + '/work', + { + ...payload, + }, + ); + + image && + (await axios + .put(res.data.imageUploadUrl, image, { + headers: { 'Content-Type': image.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); + + if (!res) return false; + + if (res.status === 201) { + return res.data; + } + + return false; + } + + async function fetchListWorkById(groupId: string) { + const res = await api.get(`/work/${groupId}`); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + + async function editWork( + productId: string, + data: ProductCreate & { status: string }, + ) { + const { image, code, ...payload } = data; + + const res = await api.put( + `/work/${productId}`, + { + ...payload, + }, + ); + + image && + (await axios + .put(res.data.imageUploadUrl, image, { + headers: { 'Content-Type': image.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function deleteWork(serviceId: string) { + const res = await api.delete(`/work/${serviceId}`); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function fetchListProductByIdWork( + workId: string, + opts?: { query?: string; page?: number; pageSize?: number }, + 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>( + `/work/${workId}/product${(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; + } + return { fetchStatsProductType, fetchListProductServiceByIdType, @@ -562,6 +715,13 @@ const useProductServiceStore = defineStore('api-product-service', () => { fetchListServiceById, editService, deleteService, + + fetchListWork, + createWork, + fetchListWorkById, + editWork, + deleteWork, + fetchListProductByIdWork, }; });