From a6c208578248f86474d306efbe7d97e6f0495ffd Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:38:50 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=20myBranch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/my-branch/index.ts | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/stores/my-branch/index.ts diff --git a/src/stores/my-branch/index.ts b/src/stores/my-branch/index.ts new file mode 100644 index 00000000..97c11466 --- /dev/null +++ b/src/stores/my-branch/index.ts @@ -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, + >( + opts?: Options, + flow?: { + sessionId?: string; + refTransactionId?: string; + transactionId?: string; + }, + ): Promise { + 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( + `/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;