fix(portfolio): publish new complete forecast regardless of request window (WealthLedger/backend#55) (#156)
This commit was merged in pull request #156.
This commit is contained in:
@@ -20,6 +20,7 @@ export class ForecastService {
|
||||
lastAttempt?: InvestmentResourceMetaDto['lastAttempt'];
|
||||
membershipRevision: number;
|
||||
portfolio: InvestmentResourceMetaDto;
|
||||
replacesLatest?: boolean;
|
||||
revision: string;
|
||||
scopeKey: string;
|
||||
sources: {
|
||||
@@ -74,7 +75,7 @@ export class ForecastService {
|
||||
.map((dependency) => dependency.sync)
|
||||
.find((sync) => sync.state === 'failed');
|
||||
return {
|
||||
data: stored ? filterEvents(stored.payload as T, input.scopeKey) : null,
|
||||
data: stored ? filterEvents(stored.payload as T, input.scopeKey, stored.scopeKey) : null,
|
||||
meta: investmentResourceMeta({
|
||||
resourceKey: input.scopeKey,
|
||||
dataRevision: String(stored?.dataRevision ?? MISSING_DATA_REVISION),
|
||||
@@ -95,7 +96,7 @@ export class ForecastService {
|
||||
}
|
||||
}
|
||||
|
||||
function filterEvents<T extends object>(payload: T, scopeKey: string): T {
|
||||
function filterEvents<T extends object>(payload: T, scopeKey: string, savedScopeKey: string): T {
|
||||
if (!scopeKey.startsWith('events/')) return payload;
|
||||
try {
|
||||
const [, from, to] = JSON.parse(scopeKey.slice('events/'.length)) as [string, string, string];
|
||||
@@ -111,8 +112,10 @@ function filterEvents<T extends object>(payload: T, scopeKey: string): T {
|
||||
const current = totals.get(event.projectedAmount.currency) ?? { value: 0n, scale: 0 };
|
||||
totals.set(event.projectedAmount.currency, add(current, decimalFromString(event.projectedAmount.value)));
|
||||
}
|
||||
const [, savedFrom, savedTo] = JSON.parse(savedScopeKey.slice('events/'.length)) as [string, string, string];
|
||||
return {
|
||||
...value,
|
||||
window: { from: savedFrom, to: savedTo },
|
||||
events,
|
||||
incomeTotalsByCurrency: [...totals]
|
||||
.sort(([left], [right]) => left.localeCompare(right))
|
||||
|
||||
Reference in New Issue
Block a user