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;