Files
biblical-guide.com/app/api/admin/users/route.ts
Andrei 4303e48fac Fix Next.js 15 compatibility and TypeScript errors
- Update API route handlers to use async params for Next.js 15 compatibility
- Fix MUI DataGrid deprecated props (pageSize -> initialState.pagination)
- Replace Material-UI Grid components with Box for better compatibility
- Fix admin authentication system with proper request parameters
- Update permission constants to match available AdminPermission enum values
- Add missing properties to Page interface for type safety
- Update .gitignore to exclude venv/, import logs, and large data directories
- Optimize Next.js config to reduce memory usage during builds

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 09:54:13 +00:00

78 lines
2.0 KiB
TypeScript

import { NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
import { getCurrentAdmin, AdminPermission, hasPermission } from '@/lib/admin-auth';
export const runtime = 'nodejs';
export async function GET(request: Request) {
try {
const admin = await getCurrentAdmin(request as any);
if (!admin || !hasPermission(admin, AdminPermission.READ_USERS)) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
);
}
const url = new URL(request.url);
const page = parseInt(url.searchParams.get('page') || '0');
const pageSize = parseInt(url.searchParams.get('pageSize') || '10');
const search = url.searchParams.get('search') || '';
const role = url.searchParams.get('role') || '';
// Build where clause for filtering
const where: any = {};
if (search) {
where.OR = [
{ email: { contains: search, mode: 'insensitive' } },
{ name: { contains: search, mode: 'insensitive' } }
];
}
if (role && role !== 'all') {
where.role = role;
}
// Get total count for pagination
const total = await prisma.user.count({ where });
// Get users with pagination
const users = await prisma.user.findMany({
where,
select: {
id: true,
email: true,
name: true,
role: true,
createdAt: true,
lastLoginAt: true,
_count: {
select: {
chatConversations: true,
prayerRequests: true,
bookmarks: true
}
}
},
orderBy: { createdAt: 'desc' },
skip: page * pageSize,
take: pageSize
});
return NextResponse.json({
users,
pagination: {
page,
pageSize,
total,
totalPages: Math.ceil(total / pageSize)
}
});
} catch (error) {
console.error('Admin users list error:', error);
return NextResponse.json(
{ error: 'Server error' },
{ status: 500 }
);
}
}