feat: add institution

This commit is contained in:
Methapon Metanipat 2024-11-07 14:00:05 +07:00
parent 4bf24dd602
commit 1290fb748e
2 changed files with 36 additions and 4 deletions

View file

@ -982,7 +982,7 @@ model WorkflowTemplateStepInstitution {
group String group String
workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id]) workflowTemplateStep WorkflowTemplateStep @relation(fields: [workflowTemplateStepId], references: [id], onDelete: Cascade)
workflowTemplateStepId String workflowTemplateStepId String
} }
@ -997,7 +997,7 @@ model WorkflowTemplateStep {
responsiblePerson WorkflowTemplateStepUser[] responsiblePerson WorkflowTemplateStepUser[]
responsibleInstitution WorkflowTemplateStepInstitution[] responsibleInstitution WorkflowTemplateStepInstitution[]
workflowTemplate WorkflowTemplate? @relation(fields: [workflowTemplateId], references: [id]) workflowTemplate WorkflowTemplate? @relation(fields: [workflowTemplateId], references: [id], onDelete: Cascade)
workflowTemplateId String? workflowTemplateId String?
} }

View file

@ -35,6 +35,7 @@ type WorkflowPayload = {
type?: string | null; type?: string | null;
value?: string[] | null; value?: string[] | null;
responsiblePersonId?: string[]; responsiblePersonId?: string[];
responsibleInstitution?: string[];
}[]; }[];
registeredBranchId?: string; registeredBranchId?: string;
status?: Status; status?: Status;
@ -81,6 +82,7 @@ export class FlowTemplateController extends Controller {
responsiblePerson: { responsiblePerson: {
include: { user: true }, include: { user: true },
}, },
responsibleInstitution: true,
}, },
}, },
}, },
@ -90,12 +92,24 @@ export class FlowTemplateController extends Controller {
}), }),
prisma.workflowTemplate.count({ where }), prisma.workflowTemplate.count({ where }),
]); ]);
return { result, page, pageSize, total };
return {
result: result.map((r) => ({
...r,
step: r.step.map((v) => ({
...v,
responsibleInstitution: v.responsibleInstitution.map((institution) => institution.group),
})),
})),
page,
pageSize,
total,
};
} }
@Get("{templateId}") @Get("{templateId}")
async getFlowTemplateById(@Request() _req: RequestWithUser, @Path() templateId: string) { async getFlowTemplateById(@Request() _req: RequestWithUser, @Path() templateId: string) {
return await prisma.workflowTemplate.findFirst({ const record = await prisma.workflowTemplate.findFirst({
include: { include: {
step: { step: {
include: { include: {
@ -103,12 +117,23 @@ export class FlowTemplateController extends Controller {
responsiblePerson: { responsiblePerson: {
include: { user: true }, include: { user: true },
}, },
responsibleInstitution: true,
}, },
}, },
}, },
where: { id: templateId }, where: { id: templateId },
orderBy: { createdAt: "asc" }, orderBy: { createdAt: "asc" },
}); });
if (!record) throw notFoundError("FlowTemplate");
return {
...record,
step: record.step.map((v) => ({
...v,
responsibleInstitution: v.responsibleInstitution.map((institution) => institution.group),
})),
};
} }
@Post() @Post()
@ -176,6 +201,9 @@ export class FlowTemplateController extends Controller {
userId: id, userId: id,
})), })),
}, },
responsibleInstitution: {
create: v.responsibleInstitution?.map((group) => ({ group })),
},
})), })),
}, },
}, },
@ -241,6 +269,10 @@ export class FlowTemplateController extends Controller {
skipDuplicates: true, skipDuplicates: true,
}, },
}, },
responsibleInstitution: {
deleteMany: {},
create: v.responsibleInstitution?.map((group) => ({ group })),
},
}, },
})), })),
}, },