From e40f62e42227b531420eaddc19ac3f639818697a Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:15:47 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E0=B9=81=E0=B8=81=E0=B9=89=20type=20=20?= =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B8=87=20work?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/product-service/index.ts | 70 +++++++++++------------------ src/stores/product-service/types.ts | 7 +++ 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 1966cf4f..caaa5e40 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -15,6 +15,9 @@ import { Service, ServiceCreate, ServiceById, + Work, + ProductOnWork, + WorkCreate, } from './types'; const useProductServiceStore = defineStore('api-product-service', () => { @@ -554,16 +557,15 @@ const useProductServiceStore = defineStore('api-product-service', () => { 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, - }, + const res = await api.get< + Pagination<(Work & { productOnWork: ProductOnWork[] })[]> + >(`/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) { @@ -573,23 +575,12 @@ const useProductServiceStore = defineStore('api-product-service', () => { return false; } - async function createWork(data: ServiceCreate) { - const { image, ...payload } = data; + async function createWork(data: WorkCreate) { + const { ...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))); + const res = await api.post('/work', { + ...payload, + }); if (!res) return false; @@ -600,8 +591,8 @@ const useProductServiceStore = defineStore('api-product-service', () => { return false; } - async function fetchListWorkById(groupId: string) { - const res = await api.get(`/work/${groupId}`); + async function fetchListWorkById(workId: string) { + const res = await api.get(`/work/${workId}`); if (!res) return false; @@ -611,25 +602,14 @@ const useProductServiceStore = defineStore('api-product-service', () => { } async function editWork( - productId: string, - data: ProductCreate & { status: string }, + workId: string, + data: WorkCreate & { status: string }, ) { - const { image, code, ...payload } = data; + const { ...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))); + const res = await api.put(`/work/${workId}`, { + ...payload, + }); if (res.status === 200) { return res.data; @@ -667,7 +647,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { const query = params.toString(); - const res = await api.get>( + const res = await api.get>( `/work/${workId}/product${(params && '?'.concat(query)) || ''}`, { headers: { diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 9e28dbe2..c85a4155 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -16,6 +16,13 @@ export interface Service { imageUrl: string; } +export interface WorkCreate { + attributes: Attributes; + productId: string[]; + name: string; + order: number; +} + export interface Work { id: string; order: number;