-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.ts
30 lines (26 loc) · 798 Bytes
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { NextResponse } from 'next/server';
import prisma from '@/app/libs/prismadb';
export async function GET() {
try {
const users = await prisma.user.findMany({
select: {
id: true,
name: true,
email: true,
image: true,
createdAt: true,
},
orderBy: {
createdAt: 'desc'
}
});
const safeUsers = users.map(user => ({
...user,
createdAt: user.createdAt.toISOString(),
}));
return NextResponse.json(safeUsers);
} catch (error) {
console.error('Error fetching users:', error);
return NextResponse.json({ message: 'Error fetching users' }, { status: 500 });
}
}