refactor: เพิ่ม fetchListMyBranch

This commit is contained in:
Net 2024-07-05 11:08:37 +07:00
parent 965b268c44
commit c58c225a13

View file

@ -8,6 +8,9 @@ import { Branch } from '../branch/types';
import useFlowStore from '../flow';
const useMyBranch = defineStore('useMyBranchStore', () => {
const myBranch = ref<Branch[]>();
const currentMyBranch = ref<Branch>();
const flowStore = useFlowStore();
async function fetchListOptionBranch<
Options extends {
@ -52,8 +55,37 @@ const useMyBranch = defineStore('useMyBranchStore', () => {
return false;
}
async function fetchListMyBranch(
userId: string,
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const res = await api.get<Pagination<Branch[]>>(`/user/${userId}/branch`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
if (res.status === 200) {
myBranch.value = res.data.result;
return res.data;
}
return false;
}
return {
myBranch,
currentMyBranch,
fetchListOptionBranch,
fetchListMyBranch,
};
});