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, CustomerUpdate,
BranchAttachmentCreate, BranchAttachmentCreate,
BranchAttachment, BranchAttachment,
CustomerStats,
CustomerBranch, CustomerBranch,
} from './types'; } from './types';
import axios from 'axios'; import axios from 'axios';
const useCustomerStore = defineStore('api-customer', () => { const useCustomerStore = defineStore('api-customer', () => {
const data = ref<Pagination<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( async function fetchList(
opts?: { opts?: {
page?: number; page?: number;
@ -54,6 +82,23 @@ const useCustomerStore = defineStore('api-customer', () => {
return false; 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( async function create(
data: CustomerCreate, data: CustomerCreate,
flow?: { flow?: {
@ -243,6 +288,9 @@ const useCustomerStore = defineStore('api-customer', () => {
return { return {
data, data,
getStatsCustomer,
fetchListById,
fetchList, fetchList,
create, create,
editById, editById,