initial commit: rocket.new export of broadcastbeat
This commit is contained in:
25
src/app/api/email/rmp/suppressions/stats/route.ts
Normal file
25
src/app/api/email/rmp/suppressions/stats/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireRmpAdmin } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = await requireRmpAdmin();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const site = searchParams.get('site') ?? '';
|
||||
|
||||
const now = new Date();
|
||||
const monthStart = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-01`;
|
||||
|
||||
let baseQuery = supabase.from('rmp_email_suppressions').select('id, suppression_type, suppressed_at');
|
||||
if (site) baseQuery = baseQuery.eq('site', site);
|
||||
|
||||
const { data: all } = await baseQuery;
|
||||
const total = (all ?? []).length;
|
||||
const added_this_month = (all ?? []).filter((s: any) => s.suppressed_at >= monthStart).length;
|
||||
const hostile_replies = (all ?? []).filter((s: any) => s.suppression_type === 'hostile_reply').length;
|
||||
|
||||
return NextResponse.json({ total, added_this_month, hostile_replies });
|
||||
}
|
||||
Reference in New Issue
Block a user