feat: อัปรูปอัน product

This commit is contained in:
Net 2024-06-18 14:00:20 +07:00
parent 459934e1ba
commit 4f8f3d3fa3
3 changed files with 31 additions and 10 deletions

View file

@ -1,6 +1,8 @@
import { defineStore } from 'pinia';
import { api } from 'src/boot/axios';
import axios from 'axios';
import { Pagination } from 'src/stores/types';
import {
@ -278,11 +280,21 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
async function createProduct(data: ProductCreate) {
const { ...payload } = data;
const { image, ...payload } = data;
const res = await api.post<ProductCreate>('/product', {
...payload,
});
const res = await api.post<ProductCreate & { imageUploadUrl: string }>(
'/product',
{
...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;

View file

@ -109,6 +109,7 @@ export interface ProductCreate {
detail: string;
name: string;
code: string;
image?: File;
}
export interface ProductUpdate {
@ -119,6 +120,7 @@ export interface ProductUpdate {
process: string;
detail: string;
name: string;
image?: File;
}
//