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;