Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
686 changes: 102 additions & 584 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"leaflet": "^1.9.4",
"leaflet.markercluster": "^1.5.3",
"lucide-react": "^0.427.0",
"next": "^16.1.1",
"next": "^14.2.0",
"next-auth": "^4.24.7",
"otplib": "^12.0.1",
"papaparse": "^5.4.1",
Expand Down
21 changes: 9 additions & 12 deletions src/app/api/documents/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ import { canAccessResource } from "@/lib/permissions";

export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const document = await prisma.document.findUnique({
where: { id },
where: { id: params.id },
include: {
author: {
select: {
Expand Down Expand Up @@ -75,21 +74,20 @@ export async function GET(

export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const data = await request.json();
const validatedData = documentSchema.parse(data);

// Check if document exists
const existingDocument = await prisma.document.findUnique({
where: { id },
where: { id: params.id },
});

if (!existingDocument) {
Expand All @@ -102,7 +100,7 @@ export async function PUT(
}

const document = await prisma.document.update({
where: { id },
where: { id: params.id },
data: {
title: validatedData.title,
type: validatedData.type,
Expand Down Expand Up @@ -155,18 +153,17 @@ export async function PUT(

export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
// Check if document exists
const document = await prisma.document.findUnique({
where: { id },
where: { id: params.id },
});

if (!document) {
Expand All @@ -193,15 +190,15 @@ export async function DELETE(

// Delete document record
await prisma.document.delete({
where: { id },
where: { id: params.id },
});

await prisma.auditLog.create({
data: {
userId: session.user.id,
action: "DELETE",
entity: "Document",
entityId: id,
entityId: params.id,
changes: JSON.stringify({ deleted: true }),
},
});
Expand Down
23 changes: 10 additions & 13 deletions src/app/api/employees/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import { employeeSchema } from "@/lib/validations";

export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const employee = await prisma.employee.findUnique({
where: { id },
where: { id: params.id },
include: {
user: {
select: {
Expand Down Expand Up @@ -88,29 +87,28 @@ export async function GET(

export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const data = await request.json();
const validatedData = employeeSchema.parse(data);

// Check if employee exists
const existingEmployee = await prisma.employee.findUnique({
where: { id },
where: { id: params.id },
});

if (!existingEmployee) {
return NextResponse.json({ error: "Employé non trouvé" }, { status: 404 });
}

const employee = await prisma.employee.update({
where: { id },
where: { id: params.id },
data: {
userId: validatedData.userId || undefined,
employeeNumber: validatedData.employeeNumber,
Expand Down Expand Up @@ -165,18 +163,17 @@ export async function PUT(

export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
// Check if employee exists
const employee = await prisma.employee.findUnique({
where: { id },
where: { id: params.id },
include: {
salaries: true,
bonuses: true,
Expand All @@ -197,13 +194,13 @@ export async function DELETE(
employee.missionAssignments.length > 0) {
// Soft delete
await prisma.employee.update({
where: { id },
where: { id: params.id },
data: { isActive: false },
});
} else {
// Hard delete if no dependencies
await prisma.employee.delete({
where: { id },
where: { id: params.id },
});
}

Expand All @@ -212,7 +209,7 @@ export async function DELETE(
userId: session.user.id,
action: "DELETE",
entity: "Employee",
entityId: id,
entityId: params.id,
changes: JSON.stringify({ deleted: true }),
},
});
Expand Down
25 changes: 11 additions & 14 deletions src/app/api/equipment/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import { equipmentSchema } from "@/lib/validations";

export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const equipment = await prisma.equipment.findUnique({
where: { id },
where: { id: params.id },
include: {
maintenances: {
orderBy: { date: "desc" },
Expand Down Expand Up @@ -66,29 +65,28 @@ export async function GET(

export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
const data = await request.json();
const validatedData = equipmentSchema.parse(data);

// Check if equipment exists
const existingEquipment = await prisma.equipment.findUnique({
where: { id },
where: { id: params.id },
});

if (!existingEquipment) {
return NextResponse.json({ error: "Équipement non trouvé" }, { status: 404 });
}

const equipment = await prisma.equipment.update({
where: { id },
where: { id: params.id },
data: {
name: validatedData.name,
category: validatedData.category,
Expand Down Expand Up @@ -134,18 +132,17 @@ export async function PUT(

export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
{ params }: { params: { id: string } }
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}

const { id } = await params;
// Check if equipment exists
const equipment = await prisma.equipment.findUnique({
where: { id },
where: { id: params.id },
include: {
maintenances: true,
missionEquipment: true,
Expand All @@ -160,7 +157,7 @@ export async function DELETE(
if (equipment.missionEquipment.length > 0) {
// Soft delete by changing status to RETIRED
await prisma.equipment.update({
where: { id },
where: { id: params.id },
data: { status: "RETIRED" },
});

Expand All @@ -169,7 +166,7 @@ export async function DELETE(
userId: session.user.id,
action: "DELETE",
entity: "Equipment",
entityId: id,
entityId: params.id,
changes: JSON.stringify({ status: "RETIRED", softDelete: true }),
},
});
Expand All @@ -181,15 +178,15 @@ export async function DELETE(
} else {
// Hard delete if no dependencies
await prisma.equipment.delete({
where: { id },
where: { id: params.id },
});

await prisma.auditLog.create({
data: {
userId: session.user.id,
action: "DELETE",
entity: "Equipment",
entityId: id,
entityId: params.id,
changes: JSON.stringify({ deleted: true }),
},
});
Expand Down
Loading