43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { prisma } from '@/lib/prisma';
|
|
import { getCurrentUser } from '@/lib/auth';
|
|
|
|
// GET - Liste tous les utilisateurs (pour sélectionner des participants)
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const user = await getCurrentUser();
|
|
if (!user) {
|
|
return NextResponse.json({ error: 'Non autorisé' }, { status: 401 });
|
|
}
|
|
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const search = searchParams.get('search');
|
|
|
|
const where: any = {};
|
|
if (search) {
|
|
where.OR = [
|
|
{ name: { contains: search } },
|
|
{ email: { contains: search } },
|
|
];
|
|
}
|
|
|
|
const users = await prisma.user.findMany({
|
|
where,
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
createdAt: true,
|
|
},
|
|
orderBy: {
|
|
name: 'asc',
|
|
},
|
|
});
|
|
|
|
return NextResponse.json(users);
|
|
} catch (error) {
|
|
console.error('Erreur lors de la récupération des utilisateurs:', error);
|
|
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 });
|
|
}
|
|
}
|