feat: เพิ่ม params ใน fetchList
This commit is contained in:
parent
42d380b13d
commit
54482648d4
1 changed files with 17 additions and 7 deletions
|
|
@ -52,21 +52,31 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function fetchById(
|
||||
async function fetchById<T extends Branch>(
|
||||
id: string,
|
||||
opts?: { includeSubBranch?: boolean },
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.get<Branch>(`/branch/${id}`, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (opts?.includeSubBranch) params.append('includeSubBranch', 'true');
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<T>(
|
||||
`/branch/${id}${(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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue