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
@@ -5,7 +5,6 @@ import {
formatDecimal,
multiply,
} from '../../../../common/decimal';
import { MoneyDto } from '../../../../common/money.dto';
import {
PortfolioDto,
@@ -19,7 +18,7 @@ const RETURN_PERCENT_DECIMAL_PLACES = 6;
export function instrumentPosition(
portfolio: PortfolioDto,
uid: string,
type: 'STOCK' | 'BOND',
type: 'BOND' | 'STOCK',
): StockPositionDto {
const positions = portfolio.positions.filter(
(p) => p.type === type && p.instrumentUid === uid,
@@ -40,8 +39,8 @@ export function instrumentPosition(
currentValue,
absoluteReturn,
averagePurchasePrice:
positive && totalCost
? {
positive && totalCost ?
{
currency: totalCost.currency,
value: formatDecimal(
divide(
@@ -50,15 +49,15 @@ export function instrumentPosition(
PRICE_DECIMAL_PLACES,
),
),
}
: null,
} :
null,
returnPercent: positive ? percent(absoluteReturn, totalCost) : null,
accounts: positions.map((p) => ({
...p,
returnPercent:
decimalFromString(p.quantity).value > 0n
? percent(p.absoluteReturn, cost(p))
: null,
decimalFromString(p.quantity).value > 0n ?
percent(p.absoluteReturn, cost(p)) :
null,
})),
isStale: portfolio.isStale,
observedAt: portfolio.lastSuccessfulAt,
@@ -66,8 +65,8 @@ export function instrumentPosition(
}
function cost(position: PortfolioPositionDto): MoneyDto | null {
const price = position.averagePurchasePrice;
return price
? {
return price ?
{
currency: price.currency,
value: formatDecimal(
multiply(
@@ -75,16 +74,17 @@ function cost(position: PortfolioPositionDto): MoneyDto | null {
decimalFromString(position.quantity),
),
),
}
: null;
} :
null;
}
function sumComplete(values: (MoneyDto | null)[]): MoneyDto | null {
const currency = values[0]?.currency;
if (
!currency ||
!values.every((v): v is MoneyDto => v !== null && v.currency === currency)
)
) {
return null;
}
return {
currency,
value: formatDecimal(
@@ -98,14 +98,15 @@ function sumComplete(values: (MoneyDto | null)[]): MoneyDto | null {
function percent(
result: MoneyDto | null,
base: MoneyDto | null,
): string | null {
): null | string {
if (
!base ||
!result ||
base.currency !== result.currency ||
decimalFromString(base.value).value <= 0n
)
) {
return null;
}
return formatDecimal(
divide(
multiply(decimalFromString(result.value), decimalFromString('100')),