refactor: organize backend by business responsibility

This commit is contained in:
2026-09-13 13:52:57 +03:00
parent 7fde3ece6e
commit 8ba005346d
145 changed files with 3027 additions and 2346 deletions
@@ -0,0 +1,106 @@
import {
Controller,
Get,
Param,
ParseUUIDPipe,
Query,
Req,
UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import type { Request } from 'express';
import { ApiProblemResponses } from '../../../../../common/decorators/api-safe-error-response.decorator';
import { AccessPayload, JwtAuthGuard } from '../../../../auth/auth.api';
import { BondIncomeService } from '../application/bond-income.service';
import { BondMarketService } from '../application/bond-market.service';
import {
BondCandlesDto,
BondCandlesQueryDto,
BondCouponsDto,
BondDto,
BondMetricsDto,
BondPositionDto,
BondQuoteDto,
BondSearchQueryDto,
BondSearchResultDto,
BondTickerParamsDto,
} from './bond.dto';
import { BondCatalogService } from '../application/bond-catalog.service';
@ApiTags('bonds')
@ApiProblemResponses()
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('bonds')
export class BondController {
constructor(
private readonly bonds: BondCatalogService,
private readonly market: BondMarketService,
private readonly income: BondIncomeService,
) {}
@Get(':uid/metrics')
@ApiOkResponse({ type: BondMetricsDto })
metrics(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
) {
return this.income.metrics(request.user.sub, uid);
}
@Get()
@ApiOkResponse({ type: [BondSearchResultDto] })
search(
@Req() request: Request & { user: AccessPayload },
@Query() query: BondSearchQueryDto,
) {
return this.bonds.search(request.user.sub, query.query);
}
@Get('by-ticker/:ticker')
@ApiOkResponse({ type: BondDto })
getByTicker(
@Req() request: Request & { user: AccessPayload },
@Param() params: BondTickerParamsDto,
) {
return this.bonds.getByTicker(request.user.sub, params.ticker);
}
@Get(':uid')
@ApiOkResponse({ type: BondDto })
get(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
) {
return this.bonds.get(request.user.sub, uid);
}
@Get(':uid/quote')
@ApiOkResponse({ type: BondQuoteDto })
quote(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
) {
return this.market.quote(request.user.sub, uid);
}
@Get(':uid/candles')
@ApiOkResponse({ type: BondCandlesDto })
candles(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
@Query() query: BondCandlesQueryDto,
) {
return this.market.candles(request.user.sub, uid, query.period);
}
@Get(':uid/position')
@ApiOkResponse({ type: BondPositionDto })
position(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
) {
return this.income.position(request.user.sub, uid);
}
@Get(':uid/coupons')
@ApiOkResponse({ type: BondCouponsDto })
coupons(
@Req() request: Request & { user: AccessPayload },
@Param('uid', new ParseUUIDPipe()) uid: string,
) {
return this.income.coupons(request.user.sub, uid);
}
}
@@ -0,0 +1,177 @@
import { ApiProperty } from '@nestjs/swagger';
import { MoneyDto } from '../../../../../common/money.dto';
import {
StockCandlesDto,
StockCandlesQueryDto,
StockPositionDto,
StockSearchQueryDto,
StockTickerParamsDto,
} from '../../stocks/presentation/stock.dto';
export class BondSearchQueryDto extends StockSearchQueryDto {}
export class BondTickerParamsDto extends StockTickerParamsDto {}
export class BondCandlesQueryDto extends StockCandlesQueryDto {}
export class BondCandlesDto extends StockCandlesDto {}
export class BondPositionDto extends StockPositionDto {}
export class BondDto {
@ApiProperty({ format: 'uuid' }) declare instrumentUid: string;
@ApiProperty({
description: 'Unambiguous ticker URL segment, or the exact instrument UID.',
})
declare slug: string;
@ApiProperty() declare name: string;
@ApiProperty({ type: String, nullable: true }) declare isin: string | null;
@ApiProperty({ type: String, nullable: true }) declare classCode:
string | null;
@ApiProperty({ type: String, nullable: true }) declare realExchange:
string | null;
@ApiProperty({ type: Boolean, nullable: true }) declare apiTradeAvailable:
boolean | null;
@ApiProperty({ type: String, nullable: true }) declare ticker: string | null;
@ApiProperty({ type: String, nullable: true }) declare logoName:
string | null;
@ApiProperty({ type: String, nullable: true }) declare currency:
string | null;
@ApiProperty({ type: String, nullable: true }) declare sector: string | null;
@ApiProperty({ type: Number, nullable: true }) declare lot: number | null;
@ApiProperty({ type: String, nullable: true, format: 'date-time' })
declare historyFrom: string | null;
@ApiProperty({ type: MoneyDto, nullable: true })
declare nominal: MoneyDto | null;
@ApiProperty({ type: MoneyDto, nullable: true })
declare initialNominal: MoneyDto | null;
@ApiProperty({ type: MoneyDto, nullable: true }) declare aci: MoneyDto | null;
@ApiProperty({ type: String, nullable: true }) declare maturityDate:
string | null;
@ApiProperty({ type: String, nullable: true }) declare callDate:
string | null;
@ApiProperty({ type: String, nullable: true }) declare bondType:
string | null;
@ApiProperty({ type: String, nullable: true }) declare riskLevel:
string | null;
@ApiProperty({ type: Number, nullable: true }) declare couponQuantityPerYear:
number | null;
@ApiProperty({ type: Boolean, nullable: true }) declare floatingCoupon:
boolean | null;
@ApiProperty({ type: Boolean, nullable: true }) declare perpetual:
boolean | null;
@ApiProperty({ type: Boolean, nullable: true }) declare amortization:
boolean | null;
@ApiProperty({ type: Boolean, nullable: true }) declare subordinated:
boolean | null;
}
export class BondSearchResultDto extends BondDto {
@ApiProperty({
type: String,
nullable: true,
description: 'Clean price in percent of nominal, not money.',
})
declare pricePercent: string | null;
@ApiProperty({ type: String, nullable: true, format: 'date-time' })
declare priceAt: string | null;
}
export class BondQuoteDto {
@ApiProperty({ type: String, nullable: true }) declare pricePercent:
string | null;
@ApiProperty({
type: MoneyDto,
nullable: true,
description:
'Indicative clean value at the current nominal; no FX conversion.',
})
declare cleanPrice: MoneyDto | null;
@ApiProperty({ type: MoneyDto, nullable: true }) declare aci: MoneyDto | null;
@ApiProperty({
type: MoneyDto,
nullable: true,
description:
'Indicative clean value plus current accrued interest, excluding fees.',
})
declare dirtyPrice: MoneyDto | null;
@ApiProperty({ type: String, nullable: true })
declare changePercentagePoints: string | null;
@ApiProperty({ type: String, nullable: true }) declare previousCloseDate:
string | null;
@ApiProperty({ type: String, nullable: true }) declare tradingStatus:
string | null;
@ApiProperty({ type: String, nullable: true, format: 'date-time' })
declare priceAt: string | null;
@ApiProperty({ type: [String] }) declare unavailable: string[];
@ApiProperty({ format: 'date-time' }) declare observedAt: string;
}
export class BondCouponDto {
@ApiProperty({ type: String, nullable: true }) declare number: string | null;
@ApiProperty({ type: String, nullable: true }) declare paymentDate:
string | null;
@ApiProperty({ type: String, nullable: true }) declare recordDate:
string | null;
@ApiProperty({ type: String, nullable: true }) declare couponType:
string | null;
@ApiProperty({ type: Number, nullable: true }) declare periodDays:
number | null;
@ApiProperty({ type: MoneyDto, nullable: true })
declare perBond: MoneyDto | null;
@ApiProperty({ type: MoneyDto, nullable: true })
declare estimatedAmount: MoneyDto | null;
@ApiProperty({ enum: ['upcoming', 'past', 'undated'] }) declare timing:
'upcoming' | 'past' | 'undated';
}
export class BondCouponsDto {
@ApiProperty({ type: [BondCouponDto] }) declare coupons: BondCouponDto[];
@ApiProperty() declare from: string;
@ApiProperty() declare to: string;
@ApiProperty() declare observedAt: string;
@ApiProperty({ type: String, nullable: true }) declare positionAt:
string | null;
@ApiProperty() declare estimateUnavailable: boolean;
@ApiProperty() declare positionIsStale: boolean;
}
export class BondYieldDto {
@ApiProperty({ description: 'MOEX effective annual yield in percent.' })
declare value: string;
@ApiProperty() declare pricePercent: string;
@ApiProperty({ format: 'date' }) declare date: string;
@ApiProperty({
type: String,
nullable: true,
description: 'MOEX yield target, e.g. MATDATE or OFFERDATE.',
})
declare dateType: string | null;
@ApiProperty({ format: 'date-time' }) declare tradeAt: string;
}
export class BondCreditRatingDto {
@ApiProperty({ enum: ['NCR'] }) declare agency: 'NCR';
@ApiProperty({ type: String, nullable: true }) declare value: string | null;
@ApiProperty({ enum: ['active', 'withdrawn'] }) declare status:
'active' | 'withdrawn';
@ApiProperty({ format: 'date' }) declare date: string;
@ApiProperty({ format: 'uri' }) declare sourceUrl: string;
@ApiProperty({ format: 'date-time' }) declare observedAt: string;
}
export class BondMetricsDto {
@ApiProperty({ type: BondCreditRatingDto, nullable: true })
declare creditRating: BondCreditRatingDto | null;
@ApiProperty({ type: MoneyDto, nullable: true })
declare coupon: MoneyDto | null;
@ApiProperty({ type: String, nullable: true, format: 'date' })
declare couponDate: string | null;
@ApiProperty({ type: String, nullable: true }) declare couponType:
string | null;
@ApiProperty({ type: Number, nullable: true }) declare couponPeriodDays:
number | null;
@ApiProperty({
type: String,
nullable: true,
description:
'Next coupon × 365 / period days / indicative clean price × 100. Not yield to maturity.',
})
declare couponYieldPercent: string | null;
@ApiProperty({ type: String, nullable: true, format: 'date-time' })
declare couponYieldPriceAt: string | null;
@ApiProperty({ type: BondYieldDto, nullable: true })
declare effectiveYield: BondYieldDto | null;
@ApiProperty({ type: [String] }) declare unavailable: string[];
@ApiProperty({ format: 'date-time' }) declare observedAt: string;
}