chore: strengthen backend eslint profile

This commit is contained in:
2026-09-28 16:37:01 +03:00
committed by ksv741
parent 53b2794963
commit a970eaaf7a
179 changed files with 4485 additions and 2716 deletions
@@ -1,9 +1,9 @@
import { portfolioStructure } from './portfolio-structure';
import { PortfolioPositionDto } from '../presentation/portfolio.dto';
import { portfolioStructure } from './portfolio-structure';
const position = (
type: string,
value: string | null,
value: null | string,
currency = 'RUB',
): PortfolioPositionDto => ({
type,
@@ -1,11 +1,11 @@
import type { Money } from '../../../../common/money.types';
import {
add,
decimalFromString,
formatDecimal,
} from '../../../../common/decimal';
import type { Money } from '../../../../common/money.types';
const SHARE_PERCENT_DECIMAL_PLACES = 6;
const PERCENT_SCALED_FACTOR = 100_000_000n;
@@ -13,14 +13,14 @@ const categoryTypes = ['STOCK', 'BOND', 'OTHER', 'CASH'] as const;
// Build from positions and cash, never from totals (which already include cash).
export function portfolioStructure(
positions: { type: string; currentValue: Money | null }[],
positions: { currentValue: Money | null; type: string }[],
cash: Money[],
) {
const currencies = new Map<
string,
{
values: ReturnType<typeof decimalFromString>[];
hasNegativeValues: boolean;
values: ReturnType<typeof decimalFromString>[];
}
>();
const unvalued = new Map<string, number>();
@@ -31,14 +31,15 @@ export function portfolioStructure(
};
const index = categoryTypes.findIndex((category) => category === type);
const value = decimalFromString(money.value);
// eslint-disable-next-line security/detect-object-injection -- The numeric index belongs to the fixed portfolio category array.
group.values[index] = add(group.values[index], value);
group.hasNegativeValues ||= value.value < 0n;
currencies.set(money.currency, group);
};
for (const position of positions) {
const type = ['STOCK', 'BOND'].includes(position.type)
? position.type
: 'OTHER';
const type = ['BOND', 'STOCK'].includes(position.type) ?
position.type :
'OTHER';
if (position.currentValue) include(type, position.currentValue);
else unvalued.set(type, (unvalued.get(type) ?? 0) + 1);
}
@@ -53,21 +54,22 @@ export function portfolioStructure(
const canCalculateShares =
!unvalued.size && !group.hasNegativeValues && total.value > 0n;
const categories = group.values.map((value, index) => ({
// eslint-disable-next-line security/detect-object-injection -- The numeric index belongs to the fixed portfolio category array.
type: categoryTypes[index],
value: formatDecimal(value),
// Rounded to six decimal places using integer arithmetic. Only the
// resulting dimensionless percentage is passed to chart geometry.
sharePercent: canCalculateShares
? formatDecimal({
sharePercent: canCalculateShares ?
formatDecimal({
value:
(value.value *
10n ** BigInt(total.scale - value.scale) *
PERCENT_SCALED_FACTOR +
total.value / 2n) /
total.value,
total.value,
scale: SHARE_PERCENT_DECIMAL_PLACES,
})
: null,
}) :
null,
}));
return {
currency,
@@ -1,9 +1,10 @@
import type { Money } from '../../../../common/money.types';
import {
add,
decimalFromString,
formatDecimal,
} from '../../../../common/decimal';
import type { Money } from '../../../../common/money.types';
export function sumMoneyByCurrency(amounts: Money[]): Money[] {
const totals = new Map<string, ReturnType<typeof decimalFromString>>();