feat: อัปโหลด รูป ของ สินค้า

This commit is contained in:
Net 2024-06-21 14:51:40 +07:00
parent a774fa1afe
commit 85c7732502
2 changed files with 31 additions and 8 deletions

View file

@ -422,15 +422,26 @@ const useProductServiceStore = defineStore('api-product-service', () => {
} }
async function createService(data: ServiceCreate) { async function createService(data: ServiceCreate) {
const { ...payload } = data; const { image, ...payload } = data;
const res = await api.post<ServiceCreate>('/service', { const res = await api.post<ServiceCreate & { imageUploadUrl: string }>(
'/service',
{
...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;
if (res.status === 200) { if (res.status === 201) {
return res.data; return res.data;
} }
@ -484,11 +495,22 @@ const useProductServiceStore = defineStore('api-product-service', () => {
} }
async function editService(serviceId: string, data: ServiceCreate) { async function editService(serviceId: string, data: ServiceCreate) {
const { ...payload } = data; const { image, code, ...payload } = data;
const res = await api.put<ServiceCreate>(`/service/${serviceId}`, { const res = await api.put<ServiceCreate & { imageUploadUrl: string }>(
`/service/${serviceId}`,
{
...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;

View file

@ -39,6 +39,7 @@ export interface ServiceCreate {
detail: string; detail: string;
name: string; name: string;
code: string; code: string;
image?: File;
} }
export interface Attributes { export interface Attributes {
@ -67,7 +68,7 @@ export interface ServiceById {
} }
export interface ProductOnWork { export interface ProductOnWork {
product: Omit<ProductList, 'imageUrl'>; product: ProductList;
updatedAt: string; updatedAt: string;
updateBy: string; updateBy: string;
createdAt: string; createdAt: string;