refactor: replace ignored numeric literals with constants
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
multiply,
|
||||
} from '../../../common/decimal';
|
||||
import { MoneyDto } from '../../../common/money.dto';
|
||||
import { MILLISECONDS_PER_SECOND } from '../../../common/time';
|
||||
import { ISO_DATE_LENGTH, ISO_DATE_START, MILLISECONDS_PER_SECOND } from '../../../common/time';
|
||||
import { decimal } from '../../../integrations/tbank/decimal';
|
||||
import {
|
||||
InstrumentMetadataService,
|
||||
@@ -30,6 +30,9 @@ import {
|
||||
UpcomingEventsDto,
|
||||
UpcomingEventsQueryDto,
|
||||
} from './upcoming-events.dto';
|
||||
|
||||
const FIRST_BATCH_OFFSET = 0;
|
||||
|
||||
const DEFAULT_EVENT_WINDOW_DAYS = 30;
|
||||
const calendarReadBatchSize = 100;
|
||||
type Position = PortfolioPositionDto;
|
||||
@@ -81,7 +84,7 @@ export class UpcomingEventsService {
|
||||
);
|
||||
const uids = [...new Set(identities.map((entry) => entry.uid))];
|
||||
for (
|
||||
let offset = 0;
|
||||
let offset = FIRST_BATCH_OFFSET;
|
||||
offset < uids.length;
|
||||
offset += calendarReadBatchSize
|
||||
) {
|
||||
@@ -219,7 +222,7 @@ export function dividendEvent(
|
||||
type: 'dividend',
|
||||
date: new Date(Number(event.recordDate?.seconds) * MILLISECONDS_PER_SECOND)
|
||||
.toISOString()
|
||||
.slice(0, 10),
|
||||
.slice(ISO_DATE_START, ISO_DATE_LENGTH),
|
||||
dateKind: 'registry',
|
||||
projectedAmount: event.dividendNet ?
|
||||
projectedMoney(
|
||||
@@ -259,10 +262,10 @@ function supported(position: Position): boolean {
|
||||
}
|
||||
|
||||
function dateWindow(query: UpcomingEventsQueryDto) {
|
||||
const from = query.from ?? new Date().toISOString().slice(0, 10);
|
||||
const from = query.from ?? new Date().toISOString().slice(ISO_DATE_START, ISO_DATE_LENGTH);
|
||||
const end = new Date(`${from}T00:00:00.000Z`);
|
||||
end.setUTCDate(end.getUTCDate() + DEFAULT_EVENT_WINDOW_DAYS);
|
||||
const to = query.to ?? end.toISOString().slice(0, 10);
|
||||
const to = query.to ?? end.toISOString().slice(ISO_DATE_START, ISO_DATE_LENGTH);
|
||||
if (from > to) {
|
||||
throw new BadRequestException({ code: 'INVALID_EVENTS_PERIOD' });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user