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

View file

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