Add candidateTeam field to evaluations; update related components and API endpoints for consistency

This commit is contained in:
Julien Froidefond
2026-02-20 09:22:12 +01:00
parent f0c5d768db
commit 9fcceb2649
11 changed files with 79 additions and 38 deletions

View File

@@ -80,7 +80,7 @@ export async function PUT(
const { id } = await params;
const body = await req.json();
const { candidateName, candidateRole, evaluatorName, evaluationDate, status, findings, recommendations, dimensionScores } = body;
const { candidateName, candidateRole, candidateTeam, evaluatorName, evaluationDate, status, findings, recommendations, dimensionScores } = body;
const existing = await prisma.evaluation.findUnique({ where: { id } });
if (!existing) {
@@ -90,8 +90,12 @@ export async function PUT(
const updateData: Record<string, unknown> = {};
if (candidateName != null) updateData.candidateName = candidateName;
if (candidateRole != null) updateData.candidateRole = candidateRole;
if (candidateTeam !== undefined) updateData.candidateTeam = candidateTeam || null;
if (evaluatorName != null) updateData.evaluatorName = evaluatorName;
if (evaluationDate != null) updateData.evaluationDate = new Date(evaluationDate);
if (evaluationDate != null) {
const d = new Date(evaluationDate);
if (!isNaN(d.getTime())) updateData.evaluationDate = d;
}
if (status != null) updateData.status = status;
if (findings != null) updateData.findings = findings;
if (recommendations != null) updateData.recommendations = recommendations;
@@ -106,14 +110,12 @@ export async function PUT(
});
}
const evaluation = await prisma.evaluation.update({
where: { id },
data: updateData,
include: {
template: { include: { dimensions: { orderBy: { orderIndex: "asc" } } } },
dimensionScores: { include: { dimension: true } },
},
});
if (Object.keys(updateData).length > 0) {
await prisma.evaluation.update({
where: { id },
data: updateData as Record<string, unknown>,
});
}
if (dimensionScores && Array.isArray(dimensionScores)) {
for (const ds of dimensionScores) {
@@ -157,7 +159,8 @@ export async function PUT(
return NextResponse.json(updated);
} catch (e) {
console.error(e);
return NextResponse.json({ error: "Failed to update evaluation" }, { status: 500 });
const msg = e instanceof Error ? e.message : "Failed to update evaluation";
return NextResponse.json({ error: msg }, { status: 500 });
}
}