Implement fiscal-style research MVP flows
Some checks failed
PR Checks / typecheck-and-build (push) Has been cancelled

This commit is contained in:
2026-03-07 09:51:18 -05:00
parent f69e5b671b
commit 52136271d3
26 changed files with 2719 additions and 243 deletions

View File

@@ -1,4 +1,4 @@
import { desc, eq } from 'drizzle-orm';
import { desc, eq, inArray, max } from 'drizzle-orm';
import type { Filing } from '@/lib/types';
import { db } from '@/lib/server/db';
import { filing, filingLink } from '@/lib/server/db/schema';
@@ -87,6 +87,35 @@ export async function getFilingByAccession(accessionNumber: string) {
return row ? toFiling(row) : null;
}
export async function listLatestFilingDatesByTickers(tickers: string[]) {
const normalizedTickers = [...new Set(
tickers
.map((ticker) => ticker.trim().toUpperCase())
.filter((ticker) => ticker.length > 0)
)];
if (normalizedTickers.length === 0) {
return new Map<string, string>();
}
const rows = await db
.select({
ticker: filing.ticker,
latest_filing_date: max(filing.filing_date)
})
.from(filing)
.where(inArray(filing.ticker, normalizedTickers))
.groupBy(filing.ticker);
return new Map(
rows
.filter((row): row is { ticker: string; latest_filing_date: string } => {
return typeof row.ticker === 'string' && typeof row.latest_filing_date === 'string';
})
.map((row) => [row.ticker, row.latest_filing_date])
);
}
export async function upsertFilingsRecords(items: UpsertFilingInput[]) {
let inserted = 0;
let updated = 0;