style: align multiline ternary operators

This commit is contained in:
2026-09-28 16:37:01 +03:00
committed by ksv741
parent b78c215ff1
commit 183b7f1efd
54 changed files with 986 additions and 982 deletions
@@ -23,8 +23,8 @@ export class GetStockCompanyUseCase {
observe,
);
return {
data: result.values.instrument ?
{
data: result.values.instrument
? {
description: result.values.description ?? null,
metrics: metrics(
result.values.fundamentals ?? null,
@@ -32,8 +32,8 @@ export class GetStockCompanyUseCase {
),
unavailable: result.unavailable,
observedAt: result.observedAt,
} :
null,
}
: null,
meta: result.meta,
};
}
@@ -51,22 +51,22 @@ export function metrics(
][] = [
['marketCapitalization', 'money', null],
['peRatioTtm', 'ratio', 'TTM'],
...(bank ?
([
...(bank
? ([
['priceToBookTtm', 'ratio', 'TTM'],
['roe', 'percent', null],
] as typeof selection) :
([
] as typeof selection)
: ([
['revenueTtm', 'money', 'TTM'],
['ebitdaTtm', 'money', 'TTM'],
] as typeof selection)),
['netIncomeTtm', 'money', 'TTM'],
...(!bank ?
([
...(!bank
? ([
['totalDebtMrq', 'money', 'MRQ'],
['netDebtToEbitda', 'ratio', null],
] as typeof selection) :
[]),
] as typeof selection)
: []),
];
return selection.flatMap(([key, unit, period]) => {
// eslint-disable-next-line security/detect-object-injection -- Keys come from the fixed metric selection declared above.
@@ -74,8 +74,8 @@ export function metrics(
const currency = values.currency?.toUpperCase() || null;
return typeof value === 'number' &&
Number.isFinite(value) &&
(unit !== 'money' || currency) ?
[
(unit !== 'money' || currency)
? [
{
key,
value,
@@ -83,7 +83,7 @@ export function metrics(
period,
currency: unit === 'money' ? currency : null,
},
] :
[];
]
: [];
});
}
@@ -34,9 +34,9 @@ export class StockCatalogService {
data:
result.data?.map((item) => {
const short = stock(item);
const detail = item.detail ?
stock({ ...item.detail, uid: item.uid }) :
short;
const detail = item.detail
? stock({ ...item.detail, uid: item.uid })
: short;
const last = item.price;
return {
...detail,
@@ -44,12 +44,12 @@ export class StockCatalogService {
isin: detail.isin ?? short.isin,
apiTradeAvailable: short.apiTradeAvailable,
price:
last?.price && detail.currency ?
{
last?.price && detail.currency
? {
currency: detail.currency,
value: formatDecimal(decimal(last.price)),
} :
null,
}
: null,
priceAt: timestamp(last?.time),
};
}) ?? null,
@@ -64,9 +64,9 @@ export class StockCatalogService {
const result = await this.discovery.detail(userId, 'share', uid, observe);
return {
...result,
data: result.data ?
{ ...stock(result.data), slug: result.data.slug } :
null,
data: result.data
? { ...stock(result.data), slug: result.data.slug }
: null,
};
}
@@ -83,9 +83,9 @@ export class StockCatalogService {
);
return {
...result,
data: result.data ?
{ ...stock(result.data), slug: result.data.slug } :
null,
data: result.data
? { ...stock(result.data), slug: result.data.slug }
: null,
};
}
}
@@ -69,18 +69,18 @@ export class StockIncomeService {
throw new NotFoundException();
}
const events = sources[1].payload?.dividends;
const position = portfolio.data ?
instrumentPosition(portfolio.data, uid, 'STOCK') :
null;
const projected = events ?
stockDividends(
const position = portfolio.data
? instrumentPosition(portfolio.data, uid, 'STOCK')
: null;
const projected = events
? stockDividends(
events,
position,
{ from, to, today },
sources[1].meta.lastSuccessfulAt ?? new Date().toISOString(),
!portfolio.data,
) :
undefined;
)
: undefined;
const result = await this.forecasts.result({
userId,
revision: connection.revision,
@@ -91,9 +91,9 @@ export class StockIncomeService {
candidate:
portfolio.data && sources[0].instrument ? projected : undefined,
});
return result.data || !projected ?
result :
{
return result.data || !projected
? result
: {
data: stockDividends(
events ?? [],
null,
@@ -117,9 +117,9 @@ export function stockDividends(
const quantity =
position &&
position.accounts.length &&
position.accounts.every((p) => decimalFromString(p.quantity).value > ZERO_QUANTITY) ?
decimalFromString(position.quantity) :
null;
position.accounts.every((p) => decimalFromString(p.quantity).value > ZERO_QUANTITY)
? decimalFromString(position.quantity)
: null;
const dividends: StockDividendDto[] = events
.filter((event) => event.dividendType?.toLowerCase() !== 'cancelled')
.map((event) => {
@@ -128,29 +128,29 @@ export function stockDividends(
const lastBuyDate = timestamp(event.lastBuyDate)?.slice(ISO_DATE_START, ISO_DATE_LENGTH) ?? null;
const currency = event.dividendNet?.currency?.toUpperCase();
const perShare =
currency && event.dividendNet ?
{ currency, value: formatDecimal(decimal(event.dividendNet)) } :
null;
currency && event.dividendNet
? { currency, value: formatDecimal(decimal(event.dividendNet)) }
: null;
// A future payment can have an already-fixed register: keep the event, but do not estimate entitlement from today's holding.
const eventDate = paymentDate ?? recordDate;
const timing: StockDividendDto['timing'] = eventDate ?
eventDate >= today ?
'upcoming' :
'past' :
'undated';
const timing: StockDividendDto['timing'] = eventDate
? eventDate >= today
? 'upcoming'
: 'past'
: 'undated';
const estimatedAmount =
quantity &&
perShare &&
recordDate &&
recordDate >= today &&
timing === 'upcoming' ?
{
timing === 'upcoming'
? {
currency: perShare.currency,
value: formatDecimal(
multiply(quantity, decimalFromString(perShare.value)),
),
} :
null;
}
: null;
return {
perShare,
recordDate,
@@ -44,9 +44,9 @@ export class StockMarketService {
observe,
);
return {
data: result.values.instrument ?
stockQuote(result.values, result.unavailable, result.observedAt) :
null,
data: result.values.instrument
? stockQuote(result.values, result.unavailable, result.observedAt)
: null,
meta: result.meta,
};
}
@@ -75,20 +75,20 @@ export function stockQuote(
const priceAt = timestamp(last?.time);
const currency = share?.currency?.toUpperCase();
const price =
last?.price && currency ?
{ currency, value: formatDecimal(decimal(last.price)) } :
null;
last?.price && currency
? { currency, value: formatDecimal(decimal(last.price)) }
: null;
const previousPrice =
previous?.close && currency ?
{ currency, value: formatDecimal(decimal(previous.close)) } :
null;
previous?.close && currency
? { currency, value: formatDecimal(decimal(previous.close)) }
: null;
const difference =
price && previousPrice ?
subtract(
price && previousPrice
? subtract(
decimalFromString(price.value),
decimalFromString(previousPrice.value),
) :
null;
)
: null;
return {
price,
priceAt,
@@ -96,21 +96,21 @@ export function stockQuote(
previousCloseDate: timestamp(previous?.time)?.slice(ISO_DATE_START, ISO_DATE_LENGTH) ?? null,
previousClose: previousPrice,
change:
difference && currency ?
{ currency, value: formatDecimal(difference) } :
null,
difference && currency
? { currency, value: formatDecimal(difference) }
: null,
changePercent:
difference &&
previousPrice &&
decimalFromString(previousPrice.value).value > ZERO_AMOUNT ?
formatDecimal(
decimalFromString(previousPrice.value).value > ZERO_AMOUNT
? formatDecimal(
divide(
multiply(difference, decimalFromString('100')),
decimalFromString(previousPrice.value),
CHANGE_PERCENT_DECIMAL_PLACES,
),
) :
null,
)
: null,
unavailable,
observedAt,
};