Added Participation Page
This commit is contained in:
51
app/api/participations/route.ts
Normal file
51
app/api/participations/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user