flatten app to repo root and update docker deployment for single-stack runtime
This commit is contained in:
26
app/api/filings/[accessionNumber]/analyze/route.ts
Normal file
26
app/api/filings/[accessionNumber]/analyze/route.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
||||
import { enqueueTask } from '@/lib/server/tasks';
|
||||
|
||||
type Context = {
|
||||
params: Promise<{ accessionNumber: string }>;
|
||||
};
|
||||
|
||||
export async function POST(_request: Request, context: Context) {
|
||||
try {
|
||||
const { accessionNumber } = await context.params;
|
||||
|
||||
if (!accessionNumber || accessionNumber.trim().length < 4) {
|
||||
return jsonError('Invalid accession number');
|
||||
}
|
||||
|
||||
const task = await enqueueTask({
|
||||
taskType: 'analyze_filing',
|
||||
payload: { accessionNumber: accessionNumber.trim() },
|
||||
priority: 65
|
||||
});
|
||||
|
||||
return Response.json({ task });
|
||||
} catch (error) {
|
||||
return jsonError(asErrorMessage(error, 'Failed to queue filing analysis task'));
|
||||
}
|
||||
}
|
||||
22
app/api/filings/route.ts
Normal file
22
app/api/filings/route.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { getStoreSnapshot } from '@/lib/server/store';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
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 });
|
||||
}
|
||||
28
app/api/filings/sync/route.ts
Normal file
28
app/api/filings/sync/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { asErrorMessage, jsonError } from '@/lib/server/http';
|
||||
import { enqueueTask } from '@/lib/server/tasks';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const payload = await request.json() as {
|
||||
ticker?: string;
|
||||
limit?: number;
|
||||
};
|
||||
|
||||
if (!payload.ticker || payload.ticker.trim().length < 1) {
|
||||
return jsonError('ticker is required');
|
||||
}
|
||||
|
||||
const task = await enqueueTask({
|
||||
taskType: 'sync_filings',
|
||||
payload: {
|
||||
ticker: payload.ticker.trim().toUpperCase(),
|
||||
limit: payload.limit ?? 20
|
||||
},
|
||||
priority: 90
|
||||
});
|
||||
|
||||
return Response.json({ task });
|
||||
} catch (error) {
|
||||
return jsonError(asErrorMessage(error, 'Failed to queue filings sync task'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user