From f62a252f5c5fb2b84c43a064dc79e05f9560c5df Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Thu, 22 Aug 2024 14:30:47 +0700 Subject: [PATCH] chore: clean branch module --- src/pages/01_branch-management/MainPage.vue | 17 +- src/stores/branch/index.ts | 209 ++++---------------- 2 files changed, 40 insertions(+), 186 deletions(-) diff --git a/src/pages/01_branch-management/MainPage.vue b/src/pages/01_branch-management/MainPage.vue index 2cd2d70b..2370a4ca 100644 --- a/src/pages/01_branch-management/MainPage.vue +++ b/src/pages/01_branch-management/MainPage.vue @@ -15,7 +15,6 @@ import { Branch, BankBook, } from 'stores/branch/types'; -import { Status } from 'stores/types'; import useUtilsStore, { dialog, baseUrl } from 'stores/utils'; import EmptyAddButton from 'components/AddButton.vue'; @@ -90,7 +89,6 @@ const columns = [ const modal = ref(false); const hideStat = ref(false); const currentId = ref(''); -const currentStatus = ref('All'); const expandedTree = ref([]); const formMenuIcon = ref<{ icon: string; color: string; bgColor: string }[]>([ { @@ -224,7 +222,6 @@ const beforeBranch = ref<{ id: string; code: string }>({ }); const inputSearch = ref(''); -const fieldBranch = ref(['all', 'branchHQLabel', 'branchLabel']); const fieldDisplay = ref< ( | 'branchLabelName' @@ -638,24 +635,12 @@ function changeTitle( function handleHold(node: BranchWithChildren) { if ($q.screen.gt.xs) return; - return function (props: unknown) { + return function () { holdDialog.value = true; currentNode.value = node; }; } -async function handleImageUpload(file: File | null, url: string | null) { - if (formType.value === 'view') { - formType.value = 'edit'; - await onSubmit(); - formType.value = 'view'; - } - if (formType.value === 'edit') { - await onSubmit(); - } - imageDialog.value = false; -} - watch( () => profileFileImg.value, () => { diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index 7f87b14d..d31797ab 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -1,11 +1,11 @@ import { ref, watch } from 'vue'; import { defineStore } from 'pinia'; -import { Pagination } from '../types'; + import { api } from 'src/boot/axios'; +import useFlowStore from '../flow'; +import { Pagination } from '../types'; import { BankBook, Branch, BranchCreate } from './types'; import { BranchContact } from '../branch-contact/types'; -import axios from 'axios'; -import useFlowStore from '../flow'; import { User } from '../user/types'; type BranchId = string; @@ -37,31 +37,18 @@ const useBranchStore = defineStore('api-branch', () => { filter?: 'head' | 'sub'; }, Data extends Pagination, - >( - opts?: Options, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ): Promise { + >(opts?: Options): Promise { const params = new URLSearchParams(); for (const [k, v] of Object.entries(opts || {})) { - v !== undefined && params.append(k, v.toString()); + if (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, - }, - }, + { headers: { 'X-Rtid': flowStore.rtid } }, ); if (res && res.status === 200) { @@ -80,32 +67,18 @@ const useBranchStore = defineStore('api-branch', () => { (Options['includeContact'] extends true ? { contact: BranchContact[] } : unknown), - >( - id: string, - opts?: Options, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ): Promise { + >(id: string, opts?: Options): Promise { const params = new URLSearchParams(); for (const [k, v] of Object.entries(opts || {})) { - v !== undefined && params.append(k, v.toString()); + if (v !== undefined) params.append(k, v.toString()); } const query = params.toString(); const res = await api.get( `/branch/${id}${(params && '?'.concat(query)) || ''}`, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }, + { headers: { 'X-Rtid': flowStore.rtid } }, ); if (!res) return false; @@ -114,15 +87,7 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function create( - branch: BranchCreate, - bank?: BankBook[], - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function create(branch: BranchCreate, bank?: BankBook[]) { const { qrCodeImage, imageUrl, ...payload } = branch; const res = await api.post< @@ -134,26 +99,21 @@ const useBranchStore = defineStore('api-branch', () => { >( '/branch', { ...payload, bank: bank }, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }, + { headers: { 'X-Rtid': flowStore.rtid } }, ); - qrCodeImage && - (await axios - .put(res.data.qrCodeImageUploadUrl, qrCodeImage, { + if (qrCodeImage) { + await api + .put(`/branch/${res.data.id}/line-image`, qrCodeImage, { headers: { 'Content-Type': qrCodeImage.type }, onUploadProgress: (e) => console.log(e), }) - .catch((e) => console.error(e))); + .catch((e) => console.error(e)); + } if (imageUrl) { - await axios - .put(res.data.imageUploadUrl, imageUrl, { + await api + .put(`/branch/${res.data.id}/branch-image`, qrCodeImage, { headers: { 'Content-Type': imageUrl.type }, onUploadProgress: (e) => console.log(e), }) @@ -171,11 +131,6 @@ const useBranchStore = defineStore('api-branch', () => { qrCodeImage?: File | undefined, imageHq?: File | undefined, bank?: BankBook[], - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, ) { const { ...payload } = data; const res = await api.put< @@ -184,17 +139,13 @@ const useBranchStore = defineStore('api-branch', () => { `/branch/${id}`, { ...payload, bank: bank }, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, + headers: { 'X-Rtid': flowStore.rtid }, }, ); if (qrCodeImage) { - await axios - .put(res.data.qrCodeImageUploadUrl, qrCodeImage, { + await api + .put(`/branch/${res.data.id}/line-image`, qrCodeImage, { headers: { 'Content-Type': qrCodeImage.type }, onUploadProgress: (e) => console.log(e), }) @@ -202,8 +153,8 @@ const useBranchStore = defineStore('api-branch', () => { } if (imageHq) { - await axios - .put(res.data.imageUploadUrl, imageHq, { + await api + .put(`/branch/${res.data.id}/branch-image`, imageHq, { headers: { 'Content-Type': imageHq.type }, onUploadProgress: (e) => console.log(e), }) @@ -215,19 +166,10 @@ const useBranchStore = defineStore('api-branch', () => { return res.data; } - async function deleteById( - id: string, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function deleteById(id: string) { const res = await api.delete(`/branch/${id}`, { headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, + 'X-Rtid': flowStore.rtid, }, }); @@ -237,20 +179,9 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function getUser( - branchId: string, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function getUser(branchId: string) { const res = await api.get(`/branch/${branchId}/user`, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, + headers: { 'X-Rtid': flowStore.rtid }, }); if (!res) return false; @@ -259,20 +190,9 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function getAdmin( - branchId: string | string[], - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function getAdmin(branchId: string | string[]) { const res = await api.get(`/branch/${branchId}/admin`, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, + headers: { 'X-Rtid': flowStore.rtid }, }); if (!res) return false; @@ -282,25 +202,11 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function addUser( - branchId: string, - userId: string | string[], - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function addUser(branchId: string, userId: string | string[]) { const res = await api.post( `/branch/${branchId}/user`, { user: ([] as string[]).concat(userId) }, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }, + { headers: { 'X-Rtid': flowStore.rtid } }, ); if (!res) return false; @@ -309,21 +215,9 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function removeUser( - branchId: string, - userId: string | string[], - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function removeUser(branchId: string, userId: string | string[]) { const res = await api.delete(`/branch/${branchId}/user`, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, + headers: { 'X-Rtid': flowStore.rtid }, data: { user: ([] as string[]).concat(userId) }, }); @@ -333,19 +227,13 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function stats(flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }) { + async function stats() { const res = await api.get<{ hq: number; br: number; }>('/branch/stats', { headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, + 'X-Rtid': flowStore.rtid, }, }); @@ -355,22 +243,11 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function userStats( - userType: string, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function userStats(userType: string) { const res = await api.get( `/branch/user-stats${userType ? '?'.concat(userType) : ''}`, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, + headers: { 'X-Rtid': flowStore.rtid }, }, ); @@ -380,18 +257,10 @@ const useBranchStore = defineStore('api-branch', () => { return false; } - async function getContact( - branchId: BranchId, - force = false, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { + async function getContact(branchId: BranchId, force = false) { if (!force && contact[branchId]) return contact[branchId]; - const res = await fetchById(branchId, { includeContact: true }, flow); + const res = await fetchById(branchId, { includeContact: true }); if (res) { contact[branchId] = res.contact;