Consolidate server utilities into shared module
- Add lib/server/utils/normalize.ts with normalizeTicker, normalizeTagsOrNull, nowIso, todayIso - Add lib/server/utils/validation.ts with asRecord, asBoolean, asStringArray, asEnum - Add lib/server/utils/index.ts re-exporting all utilities - Remove duplicate lib/server/utils.ts (old file) - Update all repos and files to use shared utilities - Remove redundant ?? '' from normalizeTicker calls - Update watchlist.ts to use normalizeTagsOrNull for null-return tags
This commit is contained in:
@@ -2,6 +2,7 @@ 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';
|
||||
import { normalizeTicker, nowIso } from '@/lib/server/utils';
|
||||
|
||||
type FilingRow = typeof filing.$inferSelect;
|
||||
|
||||
@@ -90,7 +91,7 @@ export async function getFilingByAccession(accessionNumber: string) {
|
||||
export async function listLatestFilingDatesByTickers(tickers: string[]) {
|
||||
const normalizedTickers = [...new Set(
|
||||
tickers
|
||||
.map((ticker) => ticker.trim().toUpperCase())
|
||||
.map((ticker) => normalizeTicker(ticker))
|
||||
.filter((ticker) => ticker.length > 0)
|
||||
)];
|
||||
|
||||
@@ -121,7 +122,7 @@ export async function upsertFilingsRecords(items: UpsertFilingInput[]) {
|
||||
let updated = 0;
|
||||
|
||||
for (const item of items) {
|
||||
const now = new Date().toISOString();
|
||||
const now = nowIso();
|
||||
|
||||
const existing = await getFilingByAccession(item.accession_number);
|
||||
|
||||
@@ -192,7 +193,7 @@ export async function saveFilingAnalysis(
|
||||
.update(filing)
|
||||
.set({
|
||||
analysis,
|
||||
updated_at: new Date().toISOString()
|
||||
updated_at: nowIso()
|
||||
})
|
||||
.where(eq(filing.accession_number, accessionNumber))
|
||||
.returning();
|
||||
@@ -208,7 +209,7 @@ export async function updateFilingMetricsById(
|
||||
.update(filing)
|
||||
.set({
|
||||
metrics,
|
||||
updated_at: new Date().toISOString()
|
||||
updated_at: nowIso()
|
||||
})
|
||||
.where(eq(filing.id, filingId))
|
||||
.returning();
|
||||
|
||||
Reference in New Issue
Block a user