45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { AlertStatus, Prisma } from '.prisma/project-client';
|
|
import { getAuthorizedProjectDb } from '@/lib/project-auth';
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ projectCode: string }> }
|
|
) {
|
|
try {
|
|
const { projectCode } = await params;
|
|
const projectDbResult = await getAuthorizedProjectDb(projectCode);
|
|
|
|
if (!projectDbResult.success) {
|
|
return projectDbResult.response;
|
|
}
|
|
|
|
const status = request.nextUrl.searchParams.get('status') || 'pending';
|
|
let where: Prisma.AlertWhereInput = {};
|
|
|
|
if (status === 'resolved') {
|
|
where = { status: { in: [AlertStatus.resolved, AlertStatus.ignored] } };
|
|
} else if (status !== 'all') {
|
|
where = { status: AlertStatus.pending };
|
|
}
|
|
|
|
const alerts = await projectDbResult.prisma.alert.findMany({
|
|
where,
|
|
orderBy: { createdAt: 'desc' },
|
|
include: {
|
|
license: {
|
|
select: {
|
|
licenseKey: true,
|
|
customer: { select: { companyName: true } },
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ alerts });
|
|
} catch (error) {
|
|
console.error('获取项目告警失败:', error);
|
|
return NextResponse.json({ error: '服务器错误' }, { status: 500 });
|
|
}
|
|
}
|