Update Dockerfile and package.json to use Prisma migrations, add bcryptjs and next-auth dependencies, and enhance README instructions for database setup. Refactor Prisma schema to include password hashing for users and implement evaluation sharing functionality. Improve admin page with user management features and integrate session handling for authentication. Enhance evaluation detail page with sharing options and update API routes for access control based on user roles.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m4s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 3m4s
This commit is contained in:
@@ -1,16 +1,30 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
try {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||
}
|
||||
const { searchParams } = new URL(req.url);
|
||||
const status = searchParams.get("status");
|
||||
const templateId = searchParams.get("templateId");
|
||||
|
||||
const isAdmin = session.user.role === "admin";
|
||||
const userId = session.user.id;
|
||||
|
||||
const evaluations = await prisma.evaluation.findMany({
|
||||
where: {
|
||||
...(status && { status }),
|
||||
...(templateId && { templateId }),
|
||||
...(!isAdmin && {
|
||||
OR: [
|
||||
{ evaluatorId: userId },
|
||||
{ sharedWith: { some: { userId } } },
|
||||
],
|
||||
}),
|
||||
},
|
||||
include: {
|
||||
template: { include: { dimensions: { orderBy: { orderIndex: "asc" } } } },
|
||||
@@ -28,16 +42,22 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Non authentifié" }, { status: 401 });
|
||||
}
|
||||
const body = await req.json();
|
||||
const { candidateName, candidateRole, candidateTeam, evaluatorName, evaluationDate, templateId } = body;
|
||||
const { candidateName, candidateRole, candidateTeam, evaluationDate, templateId } = body;
|
||||
|
||||
if (!candidateName || !candidateRole || !evaluatorName || !evaluationDate || !templateId) {
|
||||
if (!candidateName || !candidateRole || !evaluationDate || !templateId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing required fields: candidateName, candidateRole, evaluatorName, evaluationDate, templateId" },
|
||||
{ error: "Missing required fields: candidateName, candidateRole, evaluationDate, templateId" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const evaluatorName = session.user.name || session.user.email || "Évaluateur";
|
||||
|
||||
const template = await prisma.template.findUnique({
|
||||
where: { id: templateId },
|
||||
include: { dimensions: { orderBy: { orderIndex: "asc" } } },
|
||||
@@ -52,6 +72,7 @@ export async function POST(req: NextRequest) {
|
||||
candidateRole,
|
||||
candidateTeam: candidateTeam || null,
|
||||
evaluatorName,
|
||||
evaluatorId: session.user.id,
|
||||
evaluationDate: new Date(evaluationDate),
|
||||
templateId,
|
||||
status: "draft",
|
||||
|
||||
Reference in New Issue
Block a user