feat: เพิ่ม myBranch
This commit is contained in:
parent
0815dd19ee
commit
a6c2085782
1 changed files with 60 additions and 0 deletions
60
src/stores/my-branch/index.ts
Normal file
60
src/stores/my-branch/index.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { api } from 'src/boot/axios';
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
|
||||||
|
import { Pagination } from '../types';
|
||||||
|
import { Branch } from '../branch/types';
|
||||||
|
|
||||||
|
import useFlowStore from '../flow';
|
||||||
|
|
||||||
|
const useMyBranch = defineStore('useMyBranchStore', () => {
|
||||||
|
const flowStore = useFlowStore();
|
||||||
|
async function fetchListOptionBranch<
|
||||||
|
Options extends {
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
zipCode?: string;
|
||||||
|
query?: string;
|
||||||
|
tree?: boolean;
|
||||||
|
filter?: 'head' | 'sub';
|
||||||
|
},
|
||||||
|
Data extends Pagination<Branch[]>,
|
||||||
|
>(
|
||||||
|
opts?: Options,
|
||||||
|
flow?: {
|
||||||
|
sessionId?: string;
|
||||||
|
refTransactionId?: string;
|
||||||
|
transactionId?: string;
|
||||||
|
},
|
||||||
|
): Promise<Data | false> {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
for (const [k, v] of Object.entries(opts || {})) {
|
||||||
|
v !== undefined && params.append(k, v.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = params.toString();
|
||||||
|
|
||||||
|
const res = await api.get<Data>(
|
||||||
|
`/branch${(params && '?'.concat(query)) || ''}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (res && res.status === 200) {
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
fetchListOptionBranch,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export default useMyBranch;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue