diff --git a/prisma/migrations/20241105013134_add_detail_field/migration.sql b/prisma/migrations/20241105013134_add_detail_field/migration.sql new file mode 100644 index 0000000..15819e3 --- /dev/null +++ b/prisma/migrations/20241105013134_add_detail_field/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "WorkflowTemplateStep" ADD COLUMN "detail" TEXT; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e5517ea..2ec15df 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -946,6 +946,7 @@ model WorkflowTemplateStep { order Int name String + detail String? type String? value WorkflowTemplateStepValue[] // NOTE: For enum or options type responsiblePerson WorkflowTemplateStepUser[] diff --git a/src/controllers/04-flow-template-controller.ts b/src/controllers/04-flow-template-controller.ts index 29260f5..ce7e1b4 100644 --- a/src/controllers/04-flow-template-controller.ts +++ b/src/controllers/04-flow-template-controller.ts @@ -31,6 +31,7 @@ type WorkflowPayload = { step: { id?: string; name: string; + detail?: string; type?: string; value?: string[]; responsiblePersonId?: string[]; @@ -112,6 +113,32 @@ export class FlowTemplateController extends Controller { @Post() async createFlowTemplate(@Request() req: RequestWithUser, @Body() body: WorkflowPayload) { + const where = { + OR: [ + { name: { contains: body.name } }, + { + step: { + some: { name: { contains: body.name } }, + }, + }, + ], + AND: { + registeredBranch: { + OR: permissionCondCompany(req.user), + }, + }, + } satisfies Prisma.WorkflowTemplateWhereInput; + + const exists = await prisma.workflowTemplate.findFirst({ where }); + + if (exists) { + throw new HttpError( + HttpStatus.BAD_REQUEST, + "Workflow template with this name already exists", + "sameNameExists", + ); + } + const userAffiliatedBranch = await prisma.branch.findFirst({ include: branchRelationPermInclude(req.user), where: body.registeredBranchId