Compare commits
2 Commits
99e1a06137
...
ebd8573299
| Author | SHA1 | Date | |
|---|---|---|---|
| ebd8573299 | |||
| 27866091bf |
@@ -0,0 +1,11 @@
|
|||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "AuditLog_evaluationId_idx" ON "AuditLog"("evaluationId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Evaluation_evaluatorId_idx" ON "Evaluation"("evaluatorId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "Evaluation_templateId_idx" ON "Evaluation"("templateId");
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "EvaluationShare_userId_idx" ON "EvaluationShare"("userId");
|
||||||
@@ -66,6 +66,9 @@ model Evaluation {
|
|||||||
isPublic Boolean @default(false) // visible par tous (ex. démo)
|
isPublic Boolean @default(false) // visible par tous (ex. démo)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
|
@@index([evaluatorId])
|
||||||
|
@@index([templateId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model EvaluationShare {
|
model EvaluationShare {
|
||||||
@@ -77,6 +80,7 @@ model EvaluationShare {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
||||||
@@unique([evaluationId, userId])
|
@@unique([evaluationId, userId])
|
||||||
|
@@index([userId])
|
||||||
}
|
}
|
||||||
|
|
||||||
model DimensionScore {
|
model DimensionScore {
|
||||||
@@ -106,4 +110,6 @@ model AuditLog {
|
|||||||
newValue String?
|
newValue String?
|
||||||
userId String?
|
userId String?
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
|
|
||||||
|
@@index([evaluationId])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,11 +72,12 @@ export async function createEvaluation(data: {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const dim of template.dimensions) {
|
await prisma.dimensionScore.createMany({
|
||||||
await prisma.dimensionScore.create({
|
data: template.dimensions.map((dim) => ({
|
||||||
data: { evaluationId: evaluation.id, dimensionId: dim.id },
|
evaluationId: evaluation.id,
|
||||||
});
|
dimensionId: dim.id,
|
||||||
}
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
revalidatePath("/dashboard");
|
revalidatePath("/dashboard");
|
||||||
return { success: true, data: { id: evaluation.id } };
|
return { success: true, data: { id: evaluation.id } };
|
||||||
@@ -177,30 +178,33 @@ export async function updateEvaluation(id: string, data: UpdateEvaluationInput):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dimensionScores && Array.isArray(dimensionScores)) {
|
if (dimensionScores && Array.isArray(dimensionScores)) {
|
||||||
for (const ds of dimensionScores) {
|
const validScores = dimensionScores.filter((ds) => ds.dimensionId);
|
||||||
if (ds.dimensionId) {
|
if (validScores.length > 0) {
|
||||||
await prisma.dimensionScore.upsert({
|
await prisma.$transaction(
|
||||||
where: {
|
validScores.map((ds) =>
|
||||||
evaluationId_dimensionId: { evaluationId: id, dimensionId: ds.dimensionId },
|
prisma.dimensionScore.upsert({
|
||||||
},
|
where: {
|
||||||
update: {
|
evaluationId_dimensionId: { evaluationId: id, dimensionId: ds.dimensionId },
|
||||||
score: ds.score,
|
},
|
||||||
justification: ds.justification,
|
update: {
|
||||||
examplesObserved: ds.examplesObserved,
|
score: ds.score,
|
||||||
confidence: ds.confidence,
|
justification: ds.justification,
|
||||||
candidateNotes: ds.candidateNotes,
|
examplesObserved: ds.examplesObserved,
|
||||||
},
|
confidence: ds.confidence,
|
||||||
create: {
|
candidateNotes: ds.candidateNotes,
|
||||||
evaluationId: id,
|
},
|
||||||
dimensionId: ds.dimensionId,
|
create: {
|
||||||
score: ds.score,
|
evaluationId: id,
|
||||||
justification: ds.justification,
|
dimensionId: ds.dimensionId,
|
||||||
examplesObserved: ds.examplesObserved,
|
score: ds.score,
|
||||||
confidence: ds.confidence,
|
justification: ds.justification,
|
||||||
candidateNotes: ds.candidateNotes,
|
examplesObserved: ds.examplesObserved,
|
||||||
},
|
confidence: ds.confidence,
|
||||||
});
|
candidateNotes: ds.candidateNotes,
|
||||||
}
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { cache } from "react";
|
||||||
import { auth } from "@/auth";
|
import { auth } from "@/auth";
|
||||||
import { prisma } from "@/lib/db";
|
import { prisma } from "@/lib/db";
|
||||||
import { canAccessEvaluation } from "@/lib/evaluation-access";
|
import { canAccessEvaluation } from "@/lib/evaluation-access";
|
||||||
@@ -62,60 +62,20 @@ export async function getEvaluation(id: string) {
|
|||||||
);
|
);
|
||||||
if (!hasAccess) return null;
|
if (!hasAccess) return null;
|
||||||
|
|
||||||
const templateId = evaluation.templateId;
|
|
||||||
const dimsRaw = evaluation.template
|
|
||||||
? ((await prisma.$queryRaw(
|
|
||||||
Prisma.sql`SELECT id, slug, title, rubric, "orderIndex", "suggestedQuestions" FROM "TemplateDimension" WHERE "templateId" = ${templateId} ORDER BY "orderIndex" ASC`
|
|
||||||
)) as { id: string; slug: string; title: string; rubric: string; orderIndex: number; suggestedQuestions: string | null }[])
|
|
||||||
: [];
|
|
||||||
|
|
||||||
const dimMap = new Map(dimsRaw.map((d) => [d.id, d]));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...evaluation,
|
...evaluation,
|
||||||
evaluationDate: evaluation.evaluationDate.toISOString(),
|
evaluationDate: evaluation.evaluationDate.toISOString(),
|
||||||
template: evaluation.template
|
|
||||||
? {
|
|
||||||
...evaluation.template,
|
|
||||||
dimensions: evaluation.template.dimensions.map((d) => {
|
|
||||||
const raw = dimMap.get(d.id);
|
|
||||||
return {
|
|
||||||
...d,
|
|
||||||
suggestedQuestions: raw?.suggestedQuestions ?? d.suggestedQuestions,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
dimensionScores: evaluation.dimensionScores.map((ds) => ({
|
|
||||||
...ds,
|
|
||||||
dimension: ds.dimension
|
|
||||||
? {
|
|
||||||
...ds.dimension,
|
|
||||||
suggestedQuestions: dimMap.get(ds.dimension.id)?.suggestedQuestions ?? ds.dimension.suggestedQuestions,
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getTemplates() {
|
export const getTemplates = cache(async () => {
|
||||||
const templates = await prisma.template.findMany({
|
const templates = await prisma.template.findMany({
|
||||||
include: {
|
include: {
|
||||||
dimensions: { orderBy: { orderIndex: "asc" } },
|
dimensions: { orderBy: { orderIndex: "asc" } },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const dimsRaw = (await prisma.$queryRaw(
|
return templates;
|
||||||
Prisma.sql`SELECT id, "templateId", slug, title, rubric, "orderIndex", "suggestedQuestions" FROM "TemplateDimension" ORDER BY "templateId", "orderIndex"`
|
});
|
||||||
)) as { id: string; templateId: string; slug: string; title: string; rubric: string; orderIndex: number; suggestedQuestions: string | null }[];
|
|
||||||
const dimMap = new Map(dimsRaw.map((d) => [d.id, d]));
|
|
||||||
return templates.map((t) => ({
|
|
||||||
...t,
|
|
||||||
dimensions: t.dimensions.map((d) => ({
|
|
||||||
...d,
|
|
||||||
suggestedQuestions: dimMap.get(d.id)?.suggestedQuestions ?? d.suggestedQuestions,
|
|
||||||
})),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUsers() {
|
export async function getUsers() {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
|
|||||||
Reference in New Issue
Block a user