feat: function ต่อ api ของ work( type ยังไม่ตรง)
This commit is contained in:
parent
85c7732502
commit
b2fad573c5
1 changed files with 163 additions and 3 deletions
|
|
@ -368,7 +368,6 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
|
||||
return false;
|
||||
}
|
||||
//
|
||||
|
||||
// Service
|
||||
async function fetchStatsService() {
|
||||
|
|
@ -427,7 +426,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
const res = await api.post<ServiceCreate & { imageUploadUrl: string }>(
|
||||
'/service',
|
||||
{
|
||||
...payload,
|
||||
...payload,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -500,7 +499,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
const res = await api.put<ServiceCreate & { imageUploadUrl: string }>(
|
||||
`/service/${serviceId}`,
|
||||
{
|
||||
...payload,
|
||||
...payload,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -533,6 +532,160 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
// work
|
||||
async function fetchListWork(
|
||||
opts?: {
|
||||
query?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
baseonly?: boolean;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
for (const [k, v] of Object.entries(opts || {})) {
|
||||
v !== undefined && params.append(k, v.toString());
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!res) return false;
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function createWork(data: ServiceCreate) {
|
||||
const { image, ...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)));
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 201) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function fetchListWorkById(groupId: string) {
|
||||
const res = await api.get<ProductGroup>(`/work/${groupId}`);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
|
||||
async function editWork(
|
||||
productId: string,
|
||||
data: ProductCreate & { status: string },
|
||||
) {
|
||||
const { image, code, ...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)));
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function deleteWork(serviceId: string) {
|
||||
const res = await api.delete(`/work/${serviceId}`);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
if (res.status === 200) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function fetchListProductByIdWork(
|
||||
workId: string,
|
||||
opts?: { query?: string; page?: number; pageSize?: number },
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
for (const [k, v] of Object.entries(opts || {})) {
|
||||
v !== undefined && params.append(k, v.toString());
|
||||
}
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<Pagination<ServiceById[]>>(
|
||||
`/work/${workId}/product${(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) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
fetchStatsProductType,
|
||||
fetchListProductServiceByIdType,
|
||||
|
|
@ -562,6 +715,13 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
fetchListServiceById,
|
||||
editService,
|
||||
deleteService,
|
||||
|
||||
fetchListWork,
|
||||
createWork,
|
||||
fetchListWorkById,
|
||||
editWork,
|
||||
deleteWork,
|
||||
fetchListProductByIdWork,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue