feat(01): bank qr code

This commit is contained in:
puriphatt 2024-09-05 15:25:35 +07:00
parent 77ce547978
commit 6ea964852b
5 changed files with 273 additions and 151 deletions

View file

@ -89,10 +89,13 @@ const useBranchStore = defineStore('api-branch', () => {
async function create(branch: BranchCreate, bank?: BankBook[]) {
const { qrCodeImage, imageUrl, ...payload } = branch;
const bankPayload = bank?.map(({ bankQr, ...rest }) => ({
...rest,
}));
const res = await api.post<Branch>(
'/branch',
{ ...payload, bank: bank },
{ ...payload, bank: bankPayload },
{ headers: { 'X-Rtid': flowStore.rtid } },
);
@ -114,6 +117,23 @@ const useBranchStore = defineStore('api-branch', () => {
.catch((e) => console.error(e));
}
if (res.data.bank) {
for (let i = 0; i < bank?.length; i++) {
if (bank[i].bankQr) {
await api
.put(
`/branch/${res.data.id}/bank-qr/${res.data.bank[i].id}`,
bank[i].bankQr,
{
headers: { 'Content-Type': bank[i].bankQr.type },
onUploadProgress: (e) => console.log(e),
},
)
.catch((e) => console.error(e));
}
}
}
if (!res) return false;
return res.data;
@ -127,9 +147,13 @@ const useBranchStore = defineStore('api-branch', () => {
bank?: BankBook[],
) {
const { ...payload } = data;
const bankPayload = bank?.map(({ branchId, bankQr, ...rest }) => ({
...rest,
}));
const res = await api.put<Branch>(
`/branch/${id}`,
{ ...payload, bank: bank },
{ ...payload, bank: bankPayload },
{
headers: { 'X-Rtid': flowStore.rtid },
},
@ -153,6 +177,23 @@ const useBranchStore = defineStore('api-branch', () => {
.catch((e) => console.error(e));
}
if (res.data.bank) {
for (let i = 0; i < bank?.length; i++) {
if (bank[i].bankQr) {
await api
.put(
`/branch/${res.data.id}/bank-qr/${res.data.bank[i].id}`,
bank[i].bankQr,
{
headers: { 'Content-Type': bank[i].bankQr.type },
onUploadProgress: (e) => console.log(e),
},
)
.catch((e) => console.error(e));
}
}
}
if (!res) return false;
return res.data;

View file

@ -3,12 +3,15 @@ import { BranchContact } from '../branch-contact/types';
import { Status } from '../types';
export type BankBook = {
id?: string;
bankName: string;
accountNumber: string;
bankBranch: string;
accountName: string;
accountType: string;
currentlyUse: boolean;
bankQr?: File;
branchId?: string;
};
export type Branch = {