feat: add bank to branch payload (optional)

This commit is contained in:
Methapon2001 2024-08-02 14:53:54 +07:00
parent ef1f404779
commit 3e4709d8ff
3 changed files with 41 additions and 2 deletions

View file

@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE "BranchBank" (
"id" TEXT NOT NULL,
"bankName" TEXT NOT NULL,
"accountName" TEXT NOT NULL,
"accountNumber" TEXT NOT NULL,
"branchId" TEXT,
CONSTRAINT "BranchBank_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "BranchBank" ADD CONSTRAINT "BranchBank_branchId_fkey" FOREIGN KEY ("branchId") REFERENCES "Branch"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View file

@ -217,6 +217,8 @@ model Branch {
headOffice Branch? @relation(name: "HeadOfficeRelation", fields: [headOfficeId], references: [id])
headOfficeId String?
bank BranchBank[]
status Status @default(CREATED)
statusOrder Int @default(0)
@ -236,6 +238,16 @@ model Branch {
customerRegistration Customer[]
}
model BranchBank {
id String @id @default(uuid())
bankName String
accountName String
accountNumber String
branch Branch? @relation(fields: [branchId], references: [id])
branchId String?
}
model BranchContact {
id String @id @default(uuid())
telephoneNo String

View file

@ -42,6 +42,12 @@ type BranchCreate = {
longitude: string;
latitude: string;
bank?: {
bankName: string;
accountName: string;
accountNumber: string;
}[];
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
@ -68,6 +74,12 @@ type BranchUpdate = {
districtId?: string | null;
provinceId?: string | null;
headOfficeId?: string | null;
bank?: {
bankName: string;
accountName: string;
accountNumber: string;
}[];
};
function lineImageLoc(id: string) {
@ -273,7 +285,7 @@ export class BranchController extends Controller {
"relationHQNotFound",
);
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, ...rest } = body;
const year = new Date().getFullYear();
@ -306,6 +318,7 @@ export class BranchController extends Controller {
...rest,
statusOrder: +(rest.status === "INACTIVE"),
code,
bank: bank ? { createMany: { data: bank } } : undefined,
isHeadOffice: !headOfficeId,
province: { connect: provinceId ? { id: provinceId } : undefined },
district: { connect: districtId ? { id: districtId } : undefined },
@ -401,7 +414,7 @@ export class BranchController extends Controller {
);
}
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, ...rest } = body;
const branch = await prisma.branch.findUnique({
include: {
@ -431,6 +444,7 @@ export class BranchController extends Controller {
...rest,
statusOrder: +(rest.status === "INACTIVE"),
isHeadOffice: headOfficeId !== undefined ? headOfficeId === null : undefined,
bank: bank ? { deleteMany: {}, createMany: { data: bank } } : undefined,
province: {
connect: provinceId ? { id: provinceId } : undefined,
disconnect: provinceId === null || undefined,