From 0bd3ce55a743e3bc7ec18fc5230b1912aee6b15a Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:30:29 +0700 Subject: [PATCH] feat: add bank field --- .../migration.sql | 20 +++++++++++++++++++ prisma/schema.prisma | 9 ++++++--- src/controllers/branch-controller.ts | 8 ++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20240802103017_add_field_bank/migration.sql diff --git a/prisma/migrations/20240802103017_add_field_bank/migration.sql b/prisma/migrations/20240802103017_add_field_bank/migration.sql new file mode 100644 index 0000000..1305b42 --- /dev/null +++ b/prisma/migrations/20240802103017_add_field_bank/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - Added the required column `accountType` to the `BranchBank` table without a default value. This is not possible if the table is not empty. + - Added the required column `bankBranch` to the `BranchBank` table without a default value. This is not possible if the table is not empty. + - Added the required column `currentlyUse` to the `BranchBank` table without a default value. This is not possible if the table is not empty. + - Made the column `branchId` on table `BranchBank` required. This step will fail if there are existing NULL values in that column. + +*/ +-- DropForeignKey +ALTER TABLE "BranchBank" DROP CONSTRAINT "BranchBank_branchId_fkey"; + +-- AlterTable +ALTER TABLE "BranchBank" ADD COLUMN "accountType" TEXT NOT NULL, +ADD COLUMN "bankBranch" TEXT NOT NULL, +ADD COLUMN "currentlyUse" BOOLEAN NOT NULL, +ALTER COLUMN "branchId" SET NOT NULL; + +-- AddForeignKey +ALTER TABLE "BranchBank" ADD CONSTRAINT "BranchBank_branchId_fkey" FOREIGN KEY ("branchId") REFERENCES "Branch"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7c9bbb0..d477750 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -239,13 +239,16 @@ model Branch { } model BranchBank { - id String @id @default(uuid()) + id String @id @default(uuid()) bankName String + bankBranch String accountName String accountNumber String + accountType String + currentlyUse Boolean - branch Branch? @relation(fields: [branchId], references: [id]) - branchId String? + branch Branch @relation(fields: [branchId], references: [id], onDelete: Cascade) + branchId String } model BranchContact { diff --git a/src/controllers/branch-controller.ts b/src/controllers/branch-controller.ts index 06a91f3..4003f4b 100644 --- a/src/controllers/branch-controller.ts +++ b/src/controllers/branch-controller.ts @@ -44,8 +44,11 @@ type BranchCreate = { bank?: { bankName: string; + bankBranch: string; accountName: string; accountNumber: string; + accountType: string; + currentlyUse: boolean; }[]; subDistrictId?: string | null; @@ -77,8 +80,11 @@ type BranchUpdate = { bank?: { bankName: string; + bankBranch: string; accountName: string; accountNumber: string; + accountType: string; + currentlyUse: boolean; }[]; }; @@ -199,6 +205,7 @@ export class BranchController extends Controller { subDistrict: true, }, }, + bank: true, _count: { select: { branch: true }, }, @@ -236,6 +243,7 @@ export class BranchController extends Controller { subDistrict: true, }, }, + bank: true, contact: includeContact, }, where: { id: branchId },