29 lines
923 B
TypeScript
29 lines
923 B
TypeScript
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
|
|
import { getStoreSnapshot } from '@/lib/server/store';
|
|
|
|
export async function GET(request: Request) {
|
|
const { response } = await requireAuthenticatedSession();
|
|
if (response) {
|
|
return response;
|
|
}
|
|
|
|
const url = new URL(request.url);
|
|
const tickerFilter = url.searchParams.get('ticker')?.trim().toUpperCase();
|
|
const limitValue = Number(url.searchParams.get('limit') ?? 50);
|
|
const limit = Number.isFinite(limitValue)
|
|
? Math.min(Math.max(Math.trunc(limitValue), 1), 250)
|
|
: 50;
|
|
|
|
const snapshot = await getStoreSnapshot();
|
|
const filtered = tickerFilter
|
|
? snapshot.filings.filter((filing) => filing.ticker === tickerFilter)
|
|
: snapshot.filings;
|
|
|
|
const filings = filtered
|
|
.slice()
|
|
.sort((a, b) => Date.parse(b.filing_date) - Date.parse(a.filing_date))
|
|
.slice(0, limit);
|
|
|
|
return Response.json({ filings });
|
|
}
|