From f185a5735a3ee800e14065682b81dff831537099 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:20:16 +0700 Subject: [PATCH] feat: fetchListById/ getStatsCustomer --- src/stores/customer/index.ts | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index 2232722f..d2f6828e 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -8,12 +8,40 @@ import { CustomerUpdate, BranchAttachmentCreate, BranchAttachment, + CustomerStats, CustomerBranch, } from './types'; import axios from 'axios'; const useCustomerStore = defineStore('api-customer', () => { const data = ref>(); + + async function fetchListById( + customerId: string, + flow?: { + sessionId: string; + refTransactionId: string; + transactionId: string; + }, + ) { + const res = await api.get( + `/customer/${customerId}`, + { + headers: { + 'X-Session-Id': flow?.sessionId, + 'X-Rtid': flow?.refTransactionId, + 'X-Tid': flow?.transactionId, + }, + }, + ); + + ifres: if (res && res.status === 200) { + return res.data; + } + + return false; + } + async function fetchList( opts?: { page?: number; @@ -54,6 +82,23 @@ const useCustomerStore = defineStore('api-customer', () => { return false; } + async function getStatsCustomer(flow?: { + sessionId: string; + refTransactionId: string; + transactionId: string; + }) { + const res = await api.get('/customer/type-stats', { + headers: { + 'X-Session-Id': flow?.sessionId, + 'X-Rtid': flow?.refTransactionId, + 'X-Tid': flow?.transactionId, + }, + }); + + if (!res) return false; + + return res.data; + } async function create( data: CustomerCreate, flow?: { @@ -243,6 +288,9 @@ const useCustomerStore = defineStore('api-customer', () => { return { data, + getStatsCustomer, + + fetchListById, fetchList, create, editById,