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; }