initial commit: rocket.new export of broadcastbeat
This commit is contained in:
20
src/app/api/adops/rmp/email-schedule/route.ts
Normal file
20
src/app/api/adops/rmp/email-schedule/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireAdopsAccess } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('rmp_io_extensions')
|
||||
.select('*, rmp_clients(company_name), rmp_products(name, product_type), rmp_orders(site)')
|
||||
.not('email_scheduled_date', 'is', null)
|
||||
.order('email_scheduled_date', { ascending: true });
|
||||
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
|
||||
return NextResponse.json({ schedule: data ?? [] });
|
||||
}
|
||||
29
src/app/api/adops/rmp/flights/route.ts
Normal file
29
src/app/api/adops/rmp/flights/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireAdopsAccess } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get('status');
|
||||
const site = searchParams.get('site');
|
||||
|
||||
let query = supabase
|
||||
.from('rmp_io_extensions')
|
||||
.select('*, rmp_clients(company_name), rmp_products(name), rmp_sales_staff(full_name), rmp_orders(site)')
|
||||
.in('flight_status', ['active', 'scheduled'])
|
||||
.order('start_date', { ascending: false });
|
||||
|
||||
if (status) query = query.eq('flight_status', status);
|
||||
|
||||
const { data, error } = await query;
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
|
||||
let filtered = data ?? [];
|
||||
if (site) filtered = filtered.filter((io: any) => io.rmp_orders?.site === site);
|
||||
|
||||
return NextResponse.json({ flights: filtered });
|
||||
}
|
||||
26
src/app/api/adops/rmp/ios/[id]/status/route.ts
Normal file
26
src/app/api/adops/rmp/ios/[id]/status/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireAdopsAccess } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { id } = await params;
|
||||
const supabase = await createClient();
|
||||
const body = await request.json();
|
||||
|
||||
const updates: Record<string, any> = { flight_status: body.flight_status, updated_at: new Date().toISOString() };
|
||||
if (body.flight_status === 'active' && body.reactivation_reason) {
|
||||
updates.reactivated_at = new Date().toISOString();
|
||||
updates.reactivation_reason = body.reactivation_reason;
|
||||
}
|
||||
|
||||
const { error } = await supabase.from('rmp_io_extensions').update(updates).eq('id', id);
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
72
src/app/api/adops/rmp/ios/route.ts
Normal file
72
src/app/api/adops/rmp/ios/route.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireAdopsAccess } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get('status');
|
||||
const site = searchParams.get('site');
|
||||
|
||||
let query = supabase
|
||||
.from('rmp_io_extensions')
|
||||
.select('*, rmp_clients(company_name), rmp_products(name, product_type, dimensions), rmp_sales_staff(full_name), rmp_orders(site)')
|
||||
.order('start_date', { ascending: false });
|
||||
|
||||
if (status) query = query.eq('flight_status', status);
|
||||
|
||||
const { data, error } = await query;
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
|
||||
// Filter by site via joined order
|
||||
let filtered = data ?? [];
|
||||
if (site) filtered = filtered.filter((io: any) => io.rmp_orders?.site === site);
|
||||
|
||||
// Hide pricing for adops_uploader
|
||||
if (auth.role === 'adops_uploader') {
|
||||
filtered = filtered.map((io: any) => {
|
||||
const { is_paid, ...rest } = io;
|
||||
return rest;
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ ios: filtered });
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
const body = await request.json();
|
||||
|
||||
const { data, error } = await supabase.from('rmp_io_extensions').insert({
|
||||
existing_io_id: body.existing_io_id,
|
||||
order_id: body.order_id || null,
|
||||
product_id: body.product_id || null,
|
||||
staff_id: body.staff_id || null,
|
||||
client_id: body.client_id || null,
|
||||
is_comp: body.is_comp ?? false,
|
||||
comp_reason: body.comp_reason || null,
|
||||
is_paid: body.is_paid ?? false,
|
||||
flight_status: body.flight_status ?? 'scheduled',
|
||||
start_date: body.start_date,
|
||||
end_date: body.end_date || null,
|
||||
auto_deactivate: body.auto_deactivate ?? true,
|
||||
banner_image_url: body.banner_image_url || null,
|
||||
click_through_url: body.click_through_url || null,
|
||||
alt_text: body.alt_text || null,
|
||||
email_html_url: body.email_html_url || null,
|
||||
email_scheduled_date: body.email_scheduled_date || null,
|
||||
email_list_segment: body.email_list_segment || null,
|
||||
page_url: body.page_url || null,
|
||||
newsletter_issue_date: body.newsletter_issue_date || null,
|
||||
notes: body.notes || null,
|
||||
}).select().single();
|
||||
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
return NextResponse.json({ io: data });
|
||||
}
|
||||
20
src/app/api/adops/rmp/notifications/route.ts
Normal file
20
src/app/api/adops/rmp/notifications/route.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { requireAdopsAccess } from '@/lib/accounting/rmpService';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const auth = await requireAdopsAccess();
|
||||
if (!auth) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('rmp_adops_notifications')
|
||||
.select('*')
|
||||
.order('sent_at', { ascending: false })
|
||||
.limit(100);
|
||||
|
||||
if (error) return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
|
||||
return NextResponse.json({ notifications: data ?? [] });
|
||||
}
|
||||
31
src/app/api/adops/rmp/stats/route.ts
Normal file
31
src/app/api/adops/rmp/stats/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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 today = new Date().toISOString().split('T')[0];
|
||||
const in30 = new Date(Date.now() + 30 * 86400000).toISOString().split('T')[0];
|
||||
const monthStart = `${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, '0')}-01`;
|
||||
|
||||
const [activeR, expiring30R, expiredMonthR, compedR, unpaidR, emailR] = await Promise.all([
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).eq('flight_status', 'active'),
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).in('flight_status', ['active', 'scheduled']).lte('end_date', in30).gte('end_date', today),
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).eq('flight_status', 'expired').gte('end_date', monthStart),
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).eq('is_comp', true).eq('flight_status', 'active'),
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).eq('is_paid', false).eq('flight_status', 'active'),
|
||||
supabase.from('rmp_io_extensions').select('id', { count: 'exact', head: true }).not('email_scheduled_date', 'is', null).is('email_sent_at', null),
|
||||
]);
|
||||
|
||||
return NextResponse.json({
|
||||
active: activeR.count ?? 0,
|
||||
expiring_30d: expiring30R.count ?? 0,
|
||||
expired_month: expiredMonthR.count ?? 0,
|
||||
comped: compedR.count ?? 0,
|
||||
unpaid_active: unpaidR.count ?? 0,
|
||||
email_scheduled: emailR.count ?? 0,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user