From 109494c6d7619d62a415dd1c13645215b8aab507 Mon Sep 17 00:00:00 2001 From: Kanjana Date: Thu, 24 Apr 2025 11:40:02 +0700 Subject: [PATCH] add responsibleGroup in step --- prisma/migrations/20250424042834_add/migration.sql | 11 +++++++++++ prisma/schema.prisma | 10 ++++++++++ src/controllers/04-flow-template-controller.ts | 12 ++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 prisma/migrations/20250424042834_add/migration.sql diff --git a/prisma/migrations/20250424042834_add/migration.sql b/prisma/migrations/20250424042834_add/migration.sql new file mode 100644 index 0000000..13999bc --- /dev/null +++ b/prisma/migrations/20250424042834_add/migration.sql @@ -0,0 +1,11 @@ +-- CreateTable +CREATE TABLE "WorkflowTemplateStepGroup" ( + "id" TEXT NOT NULL, + "group" TEXT NOT NULL, + "workflowTemplateStepId" TEXT NOT NULL, + + CONSTRAINT "WorkflowTemplateStepGroup_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "WorkflowTemplateStepGroup" ADD CONSTRAINT "WorkflowTemplateStepGroup_workflowTemplateStepId_fkey" FOREIGN KEY ("workflowTemplateStepId") REFERENCES "WorkflowTemplateStep"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ab8414b..bc100b5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1089,6 +1089,15 @@ model WorkflowTemplateStepInstitution { workflowTemplateStepId String } +model WorkflowTemplateStepGroup { + id String @id @default(cuid()) + + group String + + workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id], onDelete: Cascade) + workflowTemplateStepId String +} + model WorkflowTemplateStep { id String @id @default(cuid()) @@ -1099,6 +1108,7 @@ model WorkflowTemplateStep { value WorkflowTemplateStepValue[] // NOTE: For enum or options type responsiblePerson WorkflowTemplateStepUser[] responsibleInstitution WorkflowTemplateStepInstitution[] + responsibleGroup WorkflowTemplateStepGroup[] messengerByArea Boolean @default(false) attributes Json? diff --git a/src/controllers/04-flow-template-controller.ts b/src/controllers/04-flow-template-controller.ts index 97bd1b9..940fd1d 100644 --- a/src/controllers/04-flow-template-controller.ts +++ b/src/controllers/04-flow-template-controller.ts @@ -37,6 +37,7 @@ type WorkflowPayload = { attributes?: { [key: string]: any }; responsiblePersonId?: string[]; responsibleInstitution?: string[]; + responsibleGroup?: string[]; messengerByArea?: boolean; }[]; registeredBranchId?: string; @@ -89,6 +90,7 @@ export class FlowTemplateController extends Controller { include: { user: true }, }, responsibleInstitution: true, + responsibleGroup: true, }, orderBy: { order: "asc" }, }, @@ -106,6 +108,7 @@ export class FlowTemplateController extends Controller { step: r.step.map((v) => ({ ...v, responsibleInstitution: v.responsibleInstitution.map((institution) => institution.group), + responsibleGroup: v.responsibleGroup.map((group) => group.group), })), })), page, @@ -126,6 +129,7 @@ export class FlowTemplateController extends Controller { include: { user: true }, }, responsibleInstitution: true, + responsibleGroup: true, }, }, }, @@ -140,6 +144,7 @@ export class FlowTemplateController extends Controller { step: record.step.map((v) => ({ ...v, responsibleInstitution: v.responsibleInstitution.map((institution) => institution.group), + responsibleGroup: v.responsibleGroup.map((group) => group.group), })), }; } @@ -215,6 +220,9 @@ export class FlowTemplateController extends Controller { responsibleInstitution: { create: v.responsibleInstitution?.map((group) => ({ group })), }, + responsibleGroup: { + create: v.responsibleGroup?.map((group) => ({ group })), + }, })), }, }, @@ -295,6 +303,10 @@ export class FlowTemplateController extends Controller { deleteMany: {}, create: v.responsibleInstitution?.map((group) => ({ group })), }, + responsibleGroup: { + deleteMany: {}, + create: v.responsibleGroup?.map((group) => ({ group })), + }, }, })), },