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,
|
Service,
|
||||||
ServiceCreate,
|
ServiceCreate,
|
||||||
ServiceById,
|
ServiceById,
|
||||||
|
Work,
|
||||||
|
ProductOnWork,
|
||||||
|
WorkCreate,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
const useProductServiceStore = defineStore('api-product-service', () => {
|
const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
|
|
@ -554,16 +557,15 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
|
|
||||||
const query = params.toString();
|
const query = params.toString();
|
||||||
|
|
||||||
const res = await api.get<Pagination<Service[]>>(
|
const res = await api.get<
|
||||||
`/work${(params && '?'.concat(query)) || ''}`,
|
Pagination<(Work & { productOnWork: ProductOnWork[] })[]>
|
||||||
{
|
>(`/work${(params && '?'.concat(query)) || ''}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Session-Id': flow?.sessionId,
|
||||||
'X-Rtid': flow?.refTransactionId,
|
'X-Rtid': flow?.refTransactionId,
|
||||||
'X-Tid': flow?.transactionId,
|
'X-Tid': flow?.transactionId,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
|
@ -573,23 +575,12 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createWork(data: ServiceCreate) {
|
async function createWork(data: WorkCreate) {
|
||||||
const { image, ...payload } = data;
|
const { ...payload } = data;
|
||||||
|
|
||||||
const res = await api.post<ServiceCreate & { imageUploadUrl: string }>(
|
const res = await api.post<WorkCreate>('/work', {
|
||||||
'/work',
|
...payload,
|
||||||
{
|
});
|
||||||
...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) return false;
|
||||||
|
|
||||||
|
|
@ -600,8 +591,8 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchListWorkById(groupId: string) {
|
async function fetchListWorkById(workId: string) {
|
||||||
const res = await api.get<ProductGroup>(`/work/${groupId}`);
|
const res = await api.get<Work>(`/work/${workId}`);
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
@ -611,25 +602,14 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function editWork(
|
async function editWork(
|
||||||
productId: string,
|
workId: string,
|
||||||
data: ProductCreate & { status: string },
|
data: WorkCreate & { status: string },
|
||||||
) {
|
) {
|
||||||
const { image, code, ...payload } = data;
|
const { ...payload } = data;
|
||||||
|
|
||||||
const res = await api.put<ProductCreate & { imageUploadUrl: string }>(
|
const res = await api.put<WorkCreate>(`/work/${workId}`, {
|
||||||
`/work/${productId}`,
|
...payload,
|
||||||
{
|
});
|
||||||
...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.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|
@ -667,7 +647,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
||||||
|
|
||||||
const query = params.toString();
|
const query = params.toString();
|
||||||
|
|
||||||
const res = await api.get<Pagination<ServiceById[]>>(
|
const res = await api.get<Pagination<ProductList[]>>(
|
||||||
`/work/${workId}/product${(params && '?'.concat(query)) || ''}`,
|
`/work/${workId}/product${(params && '?'.concat(query)) || ''}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,13 @@ export interface Service {
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WorkCreate {
|
||||||
|
attributes: Attributes;
|
||||||
|
productId: string[];
|
||||||
|
name: string;
|
||||||
|
order: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Work {
|
export interface Work {
|
||||||
id: string;
|
id: string;
|
||||||
order: number;
|
order: number;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue