fix: แก้ type

This commit is contained in:
Net 2024-06-25 14:30:29 +07:00
parent 9d16afa474
commit 9038275c89
2 changed files with 65 additions and 7 deletions

View file

@ -18,6 +18,7 @@ import {
Work, Work,
ProductOnWork, ProductOnWork,
WorkCreate, WorkCreate,
ServiceAndProduct,
} from './types'; } from './types';
import { ref } from 'vue'; import { ref } from 'vue';
@ -252,8 +253,18 @@ const useProductServiceStore = defineStore('api-product-service', () => {
// Product // Product
async function fetchStatsProduct() { async function fetchStatsProduct(opts?: { productTypeId?: string }) {
const res = await api.get('/product/stats'); 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(
`/product/stats${(params && '?'.concat(query)) || ''}`,
);
if (!res) return false; if (!res) return false;
@ -268,6 +279,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
productTypeId?: string; productTypeId?: string;
status?: string;
}, },
flow?: { flow?: {
sessionId: string; sessionId: string;
@ -395,6 +407,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
productTypeId?: string; productTypeId?: string;
status?: string;
}, },
flow?: { flow?: {
sessionId: string; sessionId: string;
@ -430,7 +443,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
} }
async function createService(data: ServiceCreate) { async function createService(data: ServiceCreate) {
const { image, status, ...payload } = data; const { image, status, productTypeId, ...payload } = data;
const res = await api.post<ServiceCreate & { imageUploadUrl: string }>( const res = await api.post<ServiceCreate & { imageUploadUrl: string }>(
'/service', '/service',
@ -506,7 +519,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
serviceId: string, serviceId: string,
data: Partial<ServiceCreate & { status: string }>, data: Partial<ServiceCreate & { status: string }>,
) { ) {
const { image, code, ...payload } = data; const { image, code, productTypeId, ...payload } = data;
if (payload.status === 'CREATED') { if (payload.status === 'CREATED') {
delete payload.status; delete payload.status;
@ -692,6 +705,46 @@ const useProductServiceStore = defineStore('api-product-service', () => {
} }
} }
async function fetchListProductAndService(
opts?: {
query?: string;
page?: number;
pageSize?: number;
productTypeId?: string;
status?: string;
},
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<ServiceAndProduct[]>>(
`/product-service${(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 { return {
workNameItems, workNameItems,
@ -732,6 +785,8 @@ const useProductServiceStore = defineStore('api-product-service', () => {
fetchListProductByIdWork, fetchListProductByIdWork,
fetchListOfWork, fetchListOfWork,
fetchListProductAndService,
}; };
}); });

View file

@ -1,11 +1,12 @@
import { Status } from '../types'; import { Status } from '../types';
import { Pagination } from 'src/stores/types'; import { Pagination } from 'src/stores/types';
export type ServiceAndProduct = (Service | ProductList) & { export type ServiceAndProduct =
type: 'product' | 'service'; | (Service & { type: 'service' })
}; | (ProductList & { type: 'product' });
export interface Service { export interface Service {
productTypeId: string;
updatedAt: string; updatedAt: string;
updateBy: string; updateBy: string;
createdAt: string; createdAt: string;
@ -52,6 +53,7 @@ export interface ServiceCreate {
code: string; code: string;
image?: File; image?: File;
status?: Status; status?: Status;
productTypeId: string;
} }
export interface Attributes { export interface Attributes {
@ -77,6 +79,7 @@ export interface ServiceById {
code: string; code: string;
id: string; id: string;
imageUrl: 'string'; imageUrl: 'string';
productTypeId: string;
} }
export interface ProductOnWork { export interface ProductOnWork {