feat: อัปรูปอัน product
This commit is contained in:
parent
459934e1ba
commit
4f8f3d3fa3
3 changed files with 31 additions and 10 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue