Refactor seed data to upsert candidates and evaluations, ensuring existing evaluations are updated without clearing previous data. Enhance the evaluation creation process with detailed scoring and justification for improved clarity and relevance.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m19s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m19s
This commit is contained in:
@@ -428,9 +428,7 @@ async function main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bootstrap demo data uniquement si la DB est vide
|
// Upsert répondants (candidates) par nom : create si absent, update si existant. Ne vide pas les évaluations.
|
||||||
const evalCount = await prisma.evaluation.count();
|
|
||||||
if (evalCount === 0) {
|
|
||||||
const template = await prisma.template.findUnique({
|
const template = await prisma.template.findUnique({
|
||||||
where: { id: "full-15" },
|
where: { id: "full-15" },
|
||||||
});
|
});
|
||||||
@@ -451,7 +449,7 @@ async function main() {
|
|||||||
orderBy: { orderIndex: "asc" },
|
orderBy: { orderIndex: "asc" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const candidates = [
|
const repondants = [
|
||||||
{
|
{
|
||||||
name: "Alice Chen",
|
name: "Alice Chen",
|
||||||
role: "Senior ML Engineer",
|
role: "Senior ML Engineer",
|
||||||
@@ -472,14 +470,21 @@ async function main() {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < candidates.length; i++) {
|
for (let i = 0; i < repondants.length; i++) {
|
||||||
const c = candidates[i];
|
const r = repondants[i];
|
||||||
const evaluation = await prisma.evaluation.create({
|
const existing = await prisma.evaluation.findFirst({
|
||||||
data: {
|
where: {
|
||||||
candidateName: c.name,
|
candidateName: r.name,
|
||||||
candidateRole: c.role,
|
evaluatorName: r.evaluator,
|
||||||
candidateTeam: c.team,
|
},
|
||||||
evaluatorName: c.evaluator,
|
orderBy: { evaluationDate: "desc" },
|
||||||
|
});
|
||||||
|
|
||||||
|
const evalData = {
|
||||||
|
candidateName: r.name,
|
||||||
|
candidateRole: r.role,
|
||||||
|
candidateTeam: r.team,
|
||||||
|
evaluatorName: r.evaluator,
|
||||||
evaluationDate: new Date(2025, 1, 15 + i),
|
evaluationDate: new Date(2025, 1, 15 + i),
|
||||||
templateId: template.id,
|
templateId: template.id,
|
||||||
status: i === 0 ? "submitted" : "draft",
|
status: i === 0 ? "submitted" : "draft",
|
||||||
@@ -491,8 +496,21 @@ async function main() {
|
|||||||
i === 0
|
i === 0
|
||||||
? "Encourager le mode plan avant implémentation. Veille sur les workflows IA."
|
? "Encourager le mode plan avant implémentation. Veille sur les workflows IA."
|
||||||
: null,
|
: null,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
let evaluation;
|
||||||
|
if (existing) {
|
||||||
|
evaluation = await prisma.evaluation.update({
|
||||||
|
where: { id: existing.id },
|
||||||
|
data: evalData,
|
||||||
});
|
});
|
||||||
|
await prisma.dimensionScore.deleteMany({ where: { evaluationId: existing.id } });
|
||||||
|
} else {
|
||||||
|
evaluation = await prisma.evaluation.create({
|
||||||
|
data: evalData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const d of dims) {
|
for (const d of dims) {
|
||||||
const score = 2 + Math.floor(Math.random() * 3);
|
const score = 2 + Math.floor(Math.random() * 3);
|
||||||
const { justification, examplesObserved } = getDemoResponse(d.slug, score);
|
const { justification, examplesObserved } = getDemoResponse(d.slug, score);
|
||||||
@@ -508,10 +526,7 @@ async function main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Seed complete: templates synced, demo evaluations created");
|
console.log("Seed complete: templates synced, répondants upserted (évaluations non vidées)");
|
||||||
} else {
|
|
||||||
console.log("Seed complete: templates synced, evaluations preserved");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user