diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index 92f3175c..08230c8d 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -11,6 +11,7 @@ import { CustomerStats, CustomerBranch, CustomerBranchCreate, + CustomerType, } from './types'; import axios from 'axios'; @@ -43,12 +44,63 @@ const useCustomerStore = defineStore('api-customer', () => { return false; } + async function fetchListBranch< + Options extends { + zipCode?: string; + customerId?: string; + includeCustomer?: boolean; + query?: string; + page?: number; + pageSize?: number; + }, + Data extends Pagination< + (CustomerBranch & + (Options['includeCustomer'] extends true + ? { customer: Customer } + : unknown))[] + >, + >( + opts?: Options, + flow?: { + sessionId: string; + refTransactionId: string; + transactionId: string; + }, + ): Promise { + 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( + `/customer-branch${(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; + } + async function fetchList< Options extends { page?: number; pageSize?: number; query?: string; includeBranch?: boolean; + customerType?: CustomerType; }, Data extends Pagination< (Customer & @@ -373,6 +425,7 @@ const useCustomerStore = defineStore('api-customer', () => { getStatsCustomer, + fetchListBranch, fetchListById, fetchList, create,