From 9038275c89692f2b7b6e461b3fa01b76fa3bdde6 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:30:29 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E0=B9=81=E0=B8=81=E0=B9=89=20=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/product-service/index.ts | 63 +++++++++++++++++++++++++++-- src/stores/product-service/types.ts | 9 +++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 717ba369..17634ac2 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -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( '/service', @@ -506,7 +519,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { serviceId: string, data: Partial, ) { - 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>( + `/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, }; }); diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 479310ce..92cbe9f7 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -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 {