From fd0cde4f422f43d25c2b909d67074234a573d850 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:25:04 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20fetchListBranch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/customer/index.ts | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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,