fix: แก้ type ของ work
This commit is contained in:
parent
b2fad573c5
commit
e40f62e422
2 changed files with 32 additions and 45 deletions
|
|
@ -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<Pagination<Service[]>>(
|
||||
`/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<ServiceCreate & { imageUploadUrl: string }>(
|
||||
'/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<WorkCreate>('/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<ProductGroup>(`/work/${groupId}`);
|
||||
async function fetchListWorkById(workId: string) {
|
||||
const res = await api.get<Work>(`/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<ProductCreate & { imageUploadUrl: string }>(
|
||||
`/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<WorkCreate>(`/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<Pagination<ServiceById[]>>(
|
||||
const res = await api.get<Pagination<ProductList[]>>(
|
||||
`/work/${workId}/product${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue