Files
MAD-Platform/app/api/participations/route.ts
2026-02-15 14:36:28 +01:00

52 lines
1.3 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
import { getCurrentUser } from '@/lib/auth';
// GET - Liste toutes les participations financières
export async function GET(request: NextRequest) {
try {
const user = await getCurrentUser();
if (!user) {
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
}
const participations = await prisma.participationFinanciere.findMany({
orderBy: { createdAt: 'desc' },
include: {
adherent: {
select: {
id: true,
nom: true,
prenom: true,
email: true,
},
},
trajet: {
select: {
id: true,
date: true,
adresseDepart: true,
adresseArrivee: true,
statut: true,
chauffeur: {
select: {
id: true,
nom: true,
prenom: true,
},
},
},
},
},
});
return NextResponse.json(participations);
} catch (error) {
console.error('Erreur lors de la récupération des participations:', error);
return NextResponse.json(
{ error: 'Erreur serveur' },
{ status: 500 }
);
}
}