fix: แก้ type
This commit is contained in:
parent
9d16afa474
commit
9038275c89
2 changed files with 65 additions and 7 deletions
|
|
@ -18,6 +18,7 @@ import {
|
|||
Work,
|
||||
ProductOnWork,
|
||||
WorkCreate,
|
||||
ServiceAndProduct,
|
||||
} from './types';
|
||||
import { ref } from 'vue';
|
||||
|
||||
|
|
@ -252,8 +253,18 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
|
||||
// Product
|
||||
|
||||
async function fetchStatsProduct() {
|
||||
const res = await api.get('/product/stats');
|
||||
async function fetchStatsProduct(opts?: { productTypeId?: 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(
|
||||
`/product/stats${(params && '?'.concat(query)) || ''}`,
|
||||
);
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
|
|
@ -268,6 +279,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
page?: number;
|
||||
pageSize?: number;
|
||||
productTypeId?: string;
|
||||
status?: string;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
|
|
@ -395,6 +407,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
page?: number;
|
||||
pageSize?: number;
|
||||
productTypeId?: string;
|
||||
status?: string;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
|
|
@ -430,7 +443,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
}
|
||||
|
||||
async function createService(data: ServiceCreate) {
|
||||
const { image, status, ...payload } = data;
|
||||
const { image, status, productTypeId, ...payload } = data;
|
||||
|
||||
const res = await api.post<ServiceCreate & { imageUploadUrl: string }>(
|
||||
'/service',
|
||||
|
|
@ -506,7 +519,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
serviceId: string,
|
||||
data: Partial<ServiceCreate & { status: string }>,
|
||||
) {
|
||||
const { image, code, ...payload } = data;
|
||||
const { image, code, productTypeId, ...payload } = data;
|
||||
|
||||
if (payload.status === 'CREATED') {
|
||||
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 {
|
||||
workNameItems,
|
||||
|
||||
|
|
@ -732,6 +785,8 @@ const useProductServiceStore = defineStore('api-product-service', () => {
|
|||
fetchListProductByIdWork,
|
||||
|
||||
fetchListOfWork,
|
||||
|
||||
fetchListProductAndService,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import { Status } from '../types';
|
||||
import { Pagination } from 'src/stores/types';
|
||||
|
||||
export type ServiceAndProduct = (Service | ProductList) & {
|
||||
type: 'product' | 'service';
|
||||
};
|
||||
export type ServiceAndProduct =
|
||||
| (Service & { type: 'service' })
|
||||
| (ProductList & { type: 'product' });
|
||||
|
||||
export interface Service {
|
||||
productTypeId: string;
|
||||
updatedAt: string;
|
||||
updateBy: string;
|
||||
createdAt: string;
|
||||
|
|
@ -52,6 +53,7 @@ export interface ServiceCreate {
|
|||
code: string;
|
||||
image?: File;
|
||||
status?: Status;
|
||||
productTypeId: string;
|
||||
}
|
||||
|
||||
export interface Attributes {
|
||||
|
|
@ -77,6 +79,7 @@ export interface ServiceById {
|
|||
code: string;
|
||||
id: string;
|
||||
imageUrl: 'string';
|
||||
productTypeId: string;
|
||||
}
|
||||
|
||||
export interface ProductOnWork {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue