From b49b6792d59b679a9cb3883e32f6b90cea83e09c Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:04:52 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E0=B9=81=E0=B8=81=E0=B9=89=20type=20=20?= =?UTF-8?q?=E0=B8=82=E0=B8=AD=E0=B8=87=20=20fetchList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/customer/index.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index d2f6828e..80e70caf 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -42,29 +42,36 @@ const useCustomerStore = defineStore('api-customer', () => { return false; } - async function fetchList( - opts?: { + async function fetchList< + Options extends { page?: number; pageSize?: number; query?: string; + includeBranch?: boolean; }, + Data extends Pagination< + (Customer & + (Options['includeBranch'] extends true + ? { branch: CustomerBranch[] } + : unknown))[] + >, + >( + opts?: Options, flow?: { sessionId: string; refTransactionId: string; transactionId: string; }, - ) { + ): Promise { const params = new URLSearchParams(); - if (opts?.pageSize && opts?.pageSize > 0) { - params.append('pageSize', `${opts.pageSize}`); + for (const [k, v] of Object.entries(opts || {})) { + v !== undefined && params.append(k, v.toString()); } - if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`); - if (opts?.query) params.append('query', opts.query); const query = params.toString(); - const res = await api.get>( + const res = await api.get( `/customer${(params && '?'.concat(query)) || ''}`, { headers: { @@ -75,10 +82,11 @@ const useCustomerStore = defineStore('api-customer', () => { }, ); - if (res && res.status === 200) { - data.value = res.data; - return data.value; + if (!res) return false; + if (res.status === 200) { + return res.data; } + return false; }