chore: clean branch module
This commit is contained in:
parent
a4afc54f2e
commit
f62a252f5c
2 changed files with 40 additions and 186 deletions
|
|
@ -15,7 +15,6 @@ import {
|
||||||
Branch,
|
Branch,
|
||||||
BankBook,
|
BankBook,
|
||||||
} from 'stores/branch/types';
|
} from 'stores/branch/types';
|
||||||
import { Status } from 'stores/types';
|
|
||||||
|
|
||||||
import useUtilsStore, { dialog, baseUrl } from 'stores/utils';
|
import useUtilsStore, { dialog, baseUrl } from 'stores/utils';
|
||||||
import EmptyAddButton from 'components/AddButton.vue';
|
import EmptyAddButton from 'components/AddButton.vue';
|
||||||
|
|
@ -90,7 +89,6 @@ const columns = [
|
||||||
const modal = ref<boolean>(false);
|
const modal = ref<boolean>(false);
|
||||||
const hideStat = ref(false);
|
const hideStat = ref(false);
|
||||||
const currentId = ref<string>('');
|
const currentId = ref<string>('');
|
||||||
const currentStatus = ref<Status | 'All'>('All');
|
|
||||||
const expandedTree = ref<string[]>([]);
|
const expandedTree = ref<string[]>([]);
|
||||||
const formMenuIcon = ref<{ icon: string; color: string; bgColor: string }[]>([
|
const formMenuIcon = ref<{ icon: string; color: string; bgColor: string }[]>([
|
||||||
{
|
{
|
||||||
|
|
@ -224,7 +222,6 @@ const beforeBranch = ref<{ id: string; code: string }>({
|
||||||
});
|
});
|
||||||
|
|
||||||
const inputSearch = ref<string>('');
|
const inputSearch = ref<string>('');
|
||||||
const fieldBranch = ref(['all', 'branchHQLabel', 'branchLabel']);
|
|
||||||
const fieldDisplay = ref<
|
const fieldDisplay = ref<
|
||||||
(
|
(
|
||||||
| 'branchLabelName'
|
| 'branchLabelName'
|
||||||
|
|
@ -638,24 +635,12 @@ function changeTitle(
|
||||||
|
|
||||||
function handleHold(node: BranchWithChildren) {
|
function handleHold(node: BranchWithChildren) {
|
||||||
if ($q.screen.gt.xs) return;
|
if ($q.screen.gt.xs) return;
|
||||||
return function (props: unknown) {
|
return function () {
|
||||||
holdDialog.value = true;
|
holdDialog.value = true;
|
||||||
currentNode.value = node;
|
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(
|
watch(
|
||||||
() => profileFileImg.value,
|
() => profileFileImg.value,
|
||||||
() => {
|
() => {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { ref, watch } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { Pagination } from '../types';
|
|
||||||
import { api } from 'src/boot/axios';
|
import { api } from 'src/boot/axios';
|
||||||
|
import useFlowStore from '../flow';
|
||||||
|
import { Pagination } from '../types';
|
||||||
import { BankBook, Branch, BranchCreate } from './types';
|
import { BankBook, Branch, BranchCreate } from './types';
|
||||||
import { BranchContact } from '../branch-contact/types';
|
import { BranchContact } from '../branch-contact/types';
|
||||||
import axios from 'axios';
|
|
||||||
import useFlowStore from '../flow';
|
|
||||||
import { User } from '../user/types';
|
import { User } from '../user/types';
|
||||||
|
|
||||||
type BranchId = string;
|
type BranchId = string;
|
||||||
|
|
@ -37,31 +37,18 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
filter?: 'head' | 'sub';
|
filter?: 'head' | 'sub';
|
||||||
},
|
},
|
||||||
Data extends Pagination<Branch[]>,
|
Data extends Pagination<Branch[]>,
|
||||||
>(
|
>(opts?: Options): Promise<Data | false> {
|
||||||
opts?: Options,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
): Promise<Data | false> {
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(opts || {})) {
|
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 query = params.toString();
|
||||||
|
|
||||||
const res = await api.get<Data>(
|
const res = await api.get<Data>(
|
||||||
`/branch${(params && '?'.concat(query)) || ''}`,
|
`/branch${(params && '?'.concat(query)) || ''}`,
|
||||||
{
|
{ headers: { 'X-Rtid': flowStore.rtid } },
|
||||||
headers: {
|
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res && res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
|
|
@ -80,32 +67,18 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
(Options['includeContact'] extends true
|
(Options['includeContact'] extends true
|
||||||
? { contact: BranchContact[] }
|
? { contact: BranchContact[] }
|
||||||
: unknown),
|
: unknown),
|
||||||
>(
|
>(id: string, opts?: Options): Promise<Data | false> {
|
||||||
id: string,
|
|
||||||
opts?: Options,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
): Promise<Data | false> {
|
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(opts || {})) {
|
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 query = params.toString();
|
||||||
|
|
||||||
const res = await api.get<Data>(
|
const res = await api.get<Data>(
|
||||||
`/branch/${id}${(params && '?'.concat(query)) || ''}`,
|
`/branch/${id}${(params && '?'.concat(query)) || ''}`,
|
||||||
{
|
{ headers: { 'X-Rtid': flowStore.rtid } },
|
||||||
headers: {
|
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
@ -114,15 +87,7 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function create(
|
async function create(branch: BranchCreate, bank?: BankBook[]) {
|
||||||
branch: BranchCreate,
|
|
||||||
bank?: BankBook[],
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const { qrCodeImage, imageUrl, ...payload } = branch;
|
const { qrCodeImage, imageUrl, ...payload } = branch;
|
||||||
|
|
||||||
const res = await api.post<
|
const res = await api.post<
|
||||||
|
|
@ -134,26 +99,21 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
>(
|
>(
|
||||||
'/branch',
|
'/branch',
|
||||||
{ ...payload, bank: bank },
|
{ ...payload, bank: bank },
|
||||||
{
|
{ headers: { 'X-Rtid': flowStore.rtid } },
|
||||||
headers: {
|
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
qrCodeImage &&
|
if (qrCodeImage) {
|
||||||
(await axios
|
await api
|
||||||
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
|
.put(`/branch/${res.data.id}/line-image`, qrCodeImage, {
|
||||||
headers: { 'Content-Type': qrCodeImage.type },
|
headers: { 'Content-Type': qrCodeImage.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(e)));
|
.catch((e) => console.error(e));
|
||||||
|
}
|
||||||
|
|
||||||
if (imageUrl) {
|
if (imageUrl) {
|
||||||
await axios
|
await api
|
||||||
.put(res.data.imageUploadUrl, imageUrl, {
|
.put(`/branch/${res.data.id}/branch-image`, qrCodeImage, {
|
||||||
headers: { 'Content-Type': imageUrl.type },
|
headers: { 'Content-Type': imageUrl.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
|
|
@ -171,11 +131,6 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
qrCodeImage?: File | undefined,
|
qrCodeImage?: File | undefined,
|
||||||
imageHq?: File | undefined,
|
imageHq?: File | undefined,
|
||||||
bank?: BankBook[],
|
bank?: BankBook[],
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
) {
|
||||||
const { ...payload } = data;
|
const { ...payload } = data;
|
||||||
const res = await api.put<
|
const res = await api.put<
|
||||||
|
|
@ -184,17 +139,13 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
`/branch/${id}`,
|
`/branch/${id}`,
|
||||||
{ ...payload, bank: bank },
|
{ ...payload, bank: bank },
|
||||||
{
|
{
|
||||||
headers: {
|
headers: { 'X-Rtid': flowStore.rtid },
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (qrCodeImage) {
|
if (qrCodeImage) {
|
||||||
await axios
|
await api
|
||||||
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
|
.put(`/branch/${res.data.id}/line-image`, qrCodeImage, {
|
||||||
headers: { 'Content-Type': qrCodeImage.type },
|
headers: { 'Content-Type': qrCodeImage.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
|
|
@ -202,8 +153,8 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageHq) {
|
if (imageHq) {
|
||||||
await axios
|
await api
|
||||||
.put(res.data.imageUploadUrl, imageHq, {
|
.put(`/branch/${res.data.id}/branch-image`, imageHq, {
|
||||||
headers: { 'Content-Type': imageHq.type },
|
headers: { 'Content-Type': imageHq.type },
|
||||||
onUploadProgress: (e) => console.log(e),
|
onUploadProgress: (e) => console.log(e),
|
||||||
})
|
})
|
||||||
|
|
@ -215,19 +166,10 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteById(
|
async function deleteById(id: string) {
|
||||||
id: string,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.delete<Branch>(`/branch/${id}`, {
|
const res = await api.delete<Branch>(`/branch/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Rtid': flowStore.rtid,
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -237,20 +179,9 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUser(
|
async function getUser(branchId: string) {
|
||||||
branchId: string,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.get(`/branch/${branchId}/user`, {
|
const res = await api.get(`/branch/${branchId}/user`, {
|
||||||
headers: {
|
headers: { 'X-Rtid': flowStore.rtid },
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
@ -259,20 +190,9 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAdmin(
|
async function getAdmin(branchId: string | string[]) {
|
||||||
branchId: string | string[],
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.get<User>(`/branch/${branchId}/admin`, {
|
const res = await api.get<User>(`/branch/${branchId}/admin`, {
|
||||||
headers: {
|
headers: { 'X-Rtid': flowStore.rtid },
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
@ -282,25 +202,11 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addUser(
|
async function addUser(branchId: string, userId: string | string[]) {
|
||||||
branchId: string,
|
|
||||||
userId: string | string[],
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.post(
|
const res = await api.post(
|
||||||
`/branch/${branchId}/user`,
|
`/branch/${branchId}/user`,
|
||||||
{ user: ([] as string[]).concat(userId) },
|
{ user: ([] as string[]).concat(userId) },
|
||||||
{
|
{ headers: { 'X-Rtid': flowStore.rtid } },
|
||||||
headers: {
|
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
|
|
@ -309,21 +215,9 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeUser(
|
async function removeUser(branchId: string, userId: string | string[]) {
|
||||||
branchId: string,
|
|
||||||
userId: string | string[],
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.delete(`/branch/${branchId}/user`, {
|
const res = await api.delete(`/branch/${branchId}/user`, {
|
||||||
headers: {
|
headers: { 'X-Rtid': flowStore.rtid },
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
data: { user: ([] as string[]).concat(userId) },
|
data: { user: ([] as string[]).concat(userId) },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -333,19 +227,13 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stats(flow?: {
|
async function stats() {
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
}) {
|
|
||||||
const res = await api.get<{
|
const res = await api.get<{
|
||||||
hq: number;
|
hq: number;
|
||||||
br: number;
|
br: number;
|
||||||
}>('/branch/stats', {
|
}>('/branch/stats', {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Session-Id': flow?.sessionId,
|
'X-Rtid': flowStore.rtid,
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -355,22 +243,11 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function userStats(
|
async function userStats(userType: string) {
|
||||||
userType: string,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const res = await api.get(
|
const res = await api.get(
|
||||||
`/branch/user-stats${userType ? '?'.concat(userType) : ''}`,
|
`/branch/user-stats${userType ? '?'.concat(userType) : ''}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: { 'X-Rtid': flowStore.rtid },
|
||||||
'X-Session-Id': flow?.sessionId,
|
|
||||||
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
|
|
||||||
'X-Tid': flow?.transactionId,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -380,18 +257,10 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getContact(
|
async function getContact(branchId: BranchId, force = false) {
|
||||||
branchId: BranchId,
|
|
||||||
force = false,
|
|
||||||
flow?: {
|
|
||||||
sessionId?: string;
|
|
||||||
refTransactionId?: string;
|
|
||||||
transactionId?: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
if (!force && contact[branchId]) return contact[branchId];
|
if (!force && contact[branchId]) return contact[branchId];
|
||||||
|
|
||||||
const res = await fetchById(branchId, { includeContact: true }, flow);
|
const res = await fetchById(branchId, { includeContact: true });
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
contact[branchId] = res.contact;
|
contact[branchId] = res.contact;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue