refactor: centralize domain values and enforce numeric lint

This commit is contained in:
2026-09-13 14:37:39 +03:00
parent 8ba005346d
commit 8637ad2f34
44 changed files with 543 additions and 174 deletions
@@ -1,3 +1,4 @@
import { MILLISECONDS_PER_SECOND } from '../../../common/time';
import { BadRequestException, Injectable } from '@nestjs/common';
import {
add,
@@ -25,12 +26,14 @@ import {
UpcomingEventsQueryDto,
} from './upcoming-events.dto';
const DEFAULT_EVENT_WINDOW_DAYS = 30;
type Position = NonNullable<TbankPortfolio['positions']>[number];
type CachedEntry<T> = { expiresAt: number; promise: Promise<T> };
const positionsBatchSize = 5;
const dividendCacheTtlMs = 15 * 60_000;
const instrumentCacheTtlMs = 24 * 60 * 60_000;
const dividendCacheTtlMs = 900_000;
const instrumentCacheTtlMs = 86_400_000;
@Injectable()
export class UpcomingEventsService {
@@ -242,7 +245,9 @@ export class UpcomingEventsService {
return {
...metadata,
type: 'dividend',
date: new Date(Number(event.recordDate?.seconds) * 1000)
date: new Date(
Number(event.recordDate?.seconds) * MILLISECONDS_PER_SECOND,
)
.toISOString()
.slice(0, 10),
dateKind: 'registry',
@@ -287,7 +292,7 @@ function supported(position: Position): boolean {
function dateWindow(query: UpcomingEventsQueryDto) {
const from = query.from ?? new Date().toISOString().slice(0, 10);
const end = new Date(`${from}T00:00:00.000Z`);
end.setUTCDate(end.getUTCDate() + 30);
end.setUTCDate(end.getUTCDate() + DEFAULT_EVENT_WINDOW_DAYS);
const to = query.to ?? end.toISOString().slice(0, 10);
if (from > to)
throw new BadRequestException({ code: 'INVALID_EVENTS_PERIOD' });