feat: fetchListById/ getStatsCustomer

This commit is contained in:
Net 2024-06-07 14:20:16 +07:00
parent 05288b0250
commit f185a5735a

View file

@ -8,12 +8,40 @@ import {
CustomerUpdate,
BranchAttachmentCreate,
BranchAttachment,
CustomerStats,
CustomerBranch,
} from './types';
import axios from 'axios';
const useCustomerStore = defineStore('api-customer', () => {
const data = ref<Pagination<Customer[]>>();
async function fetchListById(
customerId: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.get<Customer & { branch: CustomerBranch[] }>(
`/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<CustomerStats>('/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,