From 85c7732502144052ae1f5b5fc11fb3b2a5128ed7 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:51:40 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B8=AD=E0=B8=B1=E0=B8=9B=E0=B9=82?= =?UTF-8?q?=E0=B8=AB=E0=B8=A5=E0=B8=94=20=20=E0=B8=A3=E0=B8=B9=E0=B8=9B=20?= =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B8=87=20=E0=B8=AA=E0=B8=B4=E0=B8=99?= =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/product-service/index.ts | 36 +++++++++++++++++++++++------ src/stores/product-service/types.ts | 3 ++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 4d436887..717f02d8 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -422,15 +422,26 @@ const useProductServiceStore = defineStore('api-product-service', () => { } async function createService(data: ServiceCreate) { - const { ...payload } = data; + const { image, ...payload } = data; - const res = await api.post('/service', { + const res = await api.post( + '/service', + { ...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 === 200) { + if (res.status === 201) { return res.data; } @@ -484,11 +495,22 @@ const useProductServiceStore = defineStore('api-product-service', () => { } async function editService(serviceId: string, data: ServiceCreate) { - const { ...payload } = data; + const { image, code, ...payload } = data; - const res = await api.put(`/service/${serviceId}`, { + const res = await api.put( + `/service/${serviceId}`, + { ...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; diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 7fb5394c..9e28dbe2 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -39,6 +39,7 @@ export interface ServiceCreate { detail: string; name: string; code: string; + image?: File; } export interface Attributes { @@ -67,7 +68,7 @@ export interface ServiceById { } export interface ProductOnWork { - product: Omit; + product: ProductList; updatedAt: string; updateBy: string; createdAt: string;