Files
biblical-guide.com/app/api/admin/content/prayer-requests/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

87 lines
2.3 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.DELETE_CONTENT)) {
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 category = url.searchParams.get('category') || '';
const status = url.searchParams.get('status') || 'all';
// Build where clause for filtering
const where: any = {};
if (search) {
where.OR = [
{ title: { contains: search, mode: 'insensitive' } },
{ description: { contains: search, mode: 'insensitive' } },
{ author: { contains: search, mode: 'insensitive' } }
];
}
if (category && category !== 'all') {
where.category = category;
}
if (status !== 'all') {
where.isActive = status === 'active';
}
// Get total count for pagination
const total = await prisma.prayerRequest.count({ where });
// Get prayer requests with pagination
const prayerRequests = await prisma.prayerRequest.findMany({
where,
select: {
id: true,
title: true,
description: true,
category: true,
author: true,
isAnonymous: true,
prayerCount: true,
isActive: true,
createdAt: true,
updatedAt: true,
user: {
select: {
id: true,
email: true,
name: true
}
}
},
orderBy: { createdAt: 'desc' },
skip: page * pageSize,
take: pageSize
});
return NextResponse.json({
prayerRequests,
pagination: {
page,
pageSize,
total,
totalPages: Math.ceil(total / pageSize)
}
});
} catch (error) {
console.error('Admin prayer requests list error:', error);
return NextResponse.json(
{ error: 'Server error' },
{ status: 500 }
);
}
}