refactor: isolate operation ranges and intents
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from '../../investment-sync-plan';
|
||||
import { OperationErrorCode } from '../domain/operation-error-code';
|
||||
import {
|
||||
confirmedOperationRanges,
|
||||
operationIntervalsOverlap,
|
||||
operationsSyncPriority,
|
||||
planOperationRead,
|
||||
@@ -196,22 +197,7 @@ export class BrokerageOperationsService {
|
||||
const plan = planOperationRead(targets, saved?.coverage ?? [], now, {
|
||||
movingEnd,
|
||||
});
|
||||
const confirmed = plan.intervals.flatMap((target) =>
|
||||
(saved?.coverage ?? [])
|
||||
.filter(
|
||||
(row) =>
|
||||
row.accountId === target.accountId &&
|
||||
(!row.instrumentUid ||
|
||||
row.instrumentUid === target.instrumentUid) &&
|
||||
row.from < target.to &&
|
||||
target.from < row.to,
|
||||
)
|
||||
.map((row) => ({
|
||||
accountId: target.accountId,
|
||||
from: new Date(Math.max(row.from.valueOf(), target.from.valueOf())),
|
||||
to: new Date(Math.min(row.to.valueOf(), target.to.valueOf())),
|
||||
})),
|
||||
);
|
||||
const confirmed = confirmedOperationRanges(plan.intervals, saved?.coverage ?? []);
|
||||
const missing = uncoveredOperationIntervals(
|
||||
plan.intervals,
|
||||
confirmed.map((range) => ({
|
||||
@@ -544,19 +530,7 @@ export class BrokerageOperationsService {
|
||||
.sort((a, b) => a.valueOf() - b.valueOf())[0] ??
|
||||
(complete ? saved?.connection.membershipAt : null) ??
|
||||
null;
|
||||
const confirmed = plan.intervals.flatMap((target) =>
|
||||
sources
|
||||
.filter(
|
||||
(row) =>
|
||||
row.accountId === target.accountId &&
|
||||
operationIntervalsOverlap(row, target),
|
||||
)
|
||||
.map((row) => ({
|
||||
accountId: target.accountId,
|
||||
from: new Date(Math.max(row.from.valueOf(), target.from.valueOf())),
|
||||
to: new Date(Math.min(row.to.valueOf(), target.to.valueOf())),
|
||||
})),
|
||||
);
|
||||
const confirmed = confirmedOperationRanges(plan.intervals, sources);
|
||||
const meta = investmentResourceMeta({
|
||||
// eslint-disable-next-line security/detect-object-injection -- The numeric index enumerates the three comparison periods.
|
||||
resourceKey: `income/${accountId}/${['selected', 'previous', 'yearAgo'][index]}/${period.key}`,
|
||||
|
||||
Reference in New Issue
Block a user