feat: add workflow step detail field

This commit is contained in:
Methapon Metanipat 2024-11-05 08:31:57 +07:00
parent b758067e14
commit 4fc88b9872
3 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "WorkflowTemplateStep" ADD COLUMN "detail" TEXT;

View file

@ -946,6 +946,7 @@ model WorkflowTemplateStep {
order Int
name String
detail String?
type String?
value WorkflowTemplateStepValue[] // NOTE: For enum or options type
responsiblePerson WorkflowTemplateStepUser[]

View file

@ -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