refactor: replace ignored numeric literals with constants
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Failing after 2m17s
Conventional commits / commits (pull_request) Successful in 31s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Failing after 1m56s
Backend security / security (push) Successful in 8s
Backend verify / verify (push) Failing after 2m17s
Conventional commits / commits (pull_request) Successful in 31s
Backend security / security (pull_request) Successful in 8s
Backend verify / verify (pull_request) Failing after 1m56s
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from '../../investment-sync-plan';
|
||||
import {
|
||||
operationIntervalsOverlap,
|
||||
operationsSyncPriority,
|
||||
planOperationRead,
|
||||
uncoveredOperationIntervals,
|
||||
} from '../domain/operations-sync-plan';
|
||||
@@ -30,6 +31,14 @@ import {
|
||||
} from '../presentation/brokerage-operation.dto';
|
||||
import { BrokerageOperationsSyncService } from './brokerage-operations-sync.service';
|
||||
|
||||
const EXCLUSIVE_END_OFFSET_MS = 1;
|
||||
const FIRST_RESULT_OFFSET = 0;
|
||||
const MISSING_MEMBERSHIP_REVISION = 0;
|
||||
const STALE_FRESHNESS_MS = 0;
|
||||
const UNKNOWN_AS_OF_MS = 0;
|
||||
const LAST_ROW_INDEX = -1;
|
||||
const UNIX_EPOCH_MS = 0;
|
||||
|
||||
type LocalOperationsCursor = {
|
||||
accountId: string;
|
||||
at: string;
|
||||
@@ -106,7 +115,7 @@ export class BrokerageOperationsService {
|
||||
screen: 'operations',
|
||||
accountId,
|
||||
from: from.toISOString(),
|
||||
to: new Date(to.valueOf() - 1).toISOString(),
|
||||
to: new Date(to.valueOf() - EXCLUSIVE_END_OFFSET_MS).toISOString(),
|
||||
},
|
||||
{
|
||||
accounts: selected,
|
||||
@@ -244,7 +253,7 @@ export class BrokerageOperationsService {
|
||||
const knownBoundary = accounts.every(
|
||||
(account) => account.openedOn !== null,
|
||||
);
|
||||
const rows = saved?.rows.slice(0, limit) ?? [];
|
||||
const rows = saved?.rows.slice(FIRST_RESULT_OFFSET, limit) ?? [];
|
||||
const instruments = await this.metadata.savedMany(
|
||||
rows.map((row) => row.payload as TbankOperationItem),
|
||||
);
|
||||
@@ -278,7 +287,7 @@ export class BrokerageOperationsService {
|
||||
}
|
||||
const membershipMeta = investmentResourceMeta({
|
||||
resourceKey: 'accounts/membership',
|
||||
dataRevision: String(saved?.connection.membershipRevision ?? 0),
|
||||
dataRevision: String(saved?.connection.membershipRevision ?? MISSING_MEMBERSHIP_REVISION),
|
||||
availability: available ? 'complete' : 'missing',
|
||||
fetchedAt: saved?.connection.membershipAt ?? null,
|
||||
freshForMs: tbankSourceTtlMs.membership,
|
||||
@@ -296,7 +305,7 @@ export class BrokerageOperationsService {
|
||||
'missing',
|
||||
fetchedAt: lastSuccessfulAt,
|
||||
freshForMs: plan.intervals.some((interval) => interval.stale) ?
|
||||
0 :
|
||||
STALE_FRESHNESS_MS :
|
||||
Number.POSITIVE_INFINITY,
|
||||
work: work ?? saved?.membershipWork ?? null,
|
||||
dependencies: [membershipMeta, ...metadataDependencies],
|
||||
@@ -321,7 +330,7 @@ export class BrokerageOperationsService {
|
||||
(interval) =>
|
||||
interval.accountId === account.accountId,
|
||||
)
|
||||
.map((interval) => interval.asOf?.valueOf() ?? 0),
|
||||
.map((interval) => interval.asOf?.valueOf() ?? UNKNOWN_AS_OF_MS),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -329,11 +338,11 @@ export class BrokerageOperationsService {
|
||||
null,
|
||||
historyBoundary: knownBoundary ? 'known' : 'unknown',
|
||||
historyState: saved?.work.some(
|
||||
(work) => work.state === 'running' && work.priority > 1,
|
||||
(work) => work.state === 'running' && work.priority > operationsSyncPriority.screen,
|
||||
) ?
|
||||
'loading' :
|
||||
saved?.work.some(
|
||||
(work) => work.state === 'failed' && work.priority > 1,
|
||||
(work) => work.state === 'failed' && work.priority > operationsSyncPriority.screen,
|
||||
) ?
|
||||
'failed' :
|
||||
knownBoundary &&
|
||||
@@ -346,7 +355,7 @@ export class BrokerageOperationsService {
|
||||
'missing',
|
||||
},
|
||||
});
|
||||
const last = rows.at(-1);
|
||||
const last = rows.at(LAST_ROW_INDEX);
|
||||
const hasNext = Boolean(saved && saved.rows.length > limit);
|
||||
return {
|
||||
data:
|
||||
@@ -448,7 +457,7 @@ export class BrokerageOperationsService {
|
||||
userId,
|
||||
revision: connection.revision,
|
||||
accountId,
|
||||
from: new Date(0),
|
||||
from: new Date(UNIX_EPOCH_MS),
|
||||
to: new Date(),
|
||||
categories: ['income'],
|
||||
filterKey: `income/${accountId}`,
|
||||
@@ -486,7 +495,7 @@ export class BrokerageOperationsService {
|
||||
const now = new Date();
|
||||
const membership = investmentResourceMeta({
|
||||
resourceKey: 'accounts/membership',
|
||||
dataRevision: String(saved?.connection.membershipRevision ?? 0),
|
||||
dataRevision: String(saved?.connection.membershipRevision ?? MISSING_MEMBERSHIP_REVISION),
|
||||
availability: saved?.connection.membershipAt ? 'complete' : 'missing',
|
||||
fetchedAt: saved?.connection.membershipAt ?? null,
|
||||
freshForMs: tbankSourceTtlMs.membership,
|
||||
@@ -559,7 +568,7 @@ export class BrokerageOperationsService {
|
||||
'partial' :
|
||||
'missing',
|
||||
fetchedAt,
|
||||
freshForMs: plan.intervals.some((range) => range.stale) ? 0 : Infinity,
|
||||
freshForMs: plan.intervals.some((range) => range.stale) ? STALE_FRESHNESS_MS : Infinity,
|
||||
work,
|
||||
dependencies: [membership],
|
||||
coverage: {
|
||||
|
||||
Reference in New Issue
Block a user