136 lines
3.7 KiB
TypeScript
136 lines
3.7 KiB
TypeScript
import type { Request } from 'express';
|
|
|
|
import {
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Query,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
|
|
|
import { ApiProblemResponses } from '../../../../../common/decorators/api-safe-error-response.decorator';
|
|
import { AccessPayload, JwtAuthGuard } from '../../../../auth/auth.api';
|
|
import { InvestmentReadQueryDto } from '../../../investment-resource.dto';
|
|
import { BondCatalogService } from '../application/bond-catalog.service';
|
|
import { BondIncomeService } from '../application/bond-income.service';
|
|
import { BondMarketService } from '../application/bond-market.service';
|
|
import {
|
|
BondCandlesQueryDto,
|
|
BondCandlesResourceDto,
|
|
BondCouponsResourceDto,
|
|
BondMetricsResourceDto,
|
|
BondPositionResourceDto,
|
|
BondQuoteResourceDto,
|
|
BondResourceDto,
|
|
BondSearchQueryDto,
|
|
BondSearchResourceDto,
|
|
BondTickerParamsDto,
|
|
} from './bond.dto';
|
|
|
|
@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: BondMetricsResourceDto })
|
|
metrics(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.income.metrics(request.user.sub, uid, query.sync === 'observe');
|
|
}
|
|
|
|
@Get()
|
|
@ApiOkResponse({ type: BondSearchResourceDto })
|
|
search(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Query() query: BondSearchQueryDto,
|
|
) {
|
|
return this.bonds.search(
|
|
request.user.sub,
|
|
query.query,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get('by-ticker/:ticker')
|
|
@ApiOkResponse({ type: BondResourceDto })
|
|
getByTicker(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param() params: BondTickerParamsDto,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.bonds.getByTicker(
|
|
request.user.sub,
|
|
params.ticker,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get(':uid')
|
|
@ApiOkResponse({ type: BondResourceDto })
|
|
get(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.bonds.get(request.user.sub, uid, query.sync === 'observe');
|
|
}
|
|
|
|
@Get(':uid/quote')
|
|
@ApiOkResponse({ type: BondQuoteResourceDto })
|
|
quote(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.market.quote(request.user.sub, uid, query.sync === 'observe');
|
|
}
|
|
|
|
@Get(':uid/candles')
|
|
@ApiOkResponse({ type: BondCandlesResourceDto })
|
|
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,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get(':uid/position')
|
|
@ApiOkResponse({ type: BondPositionResourceDto })
|
|
position(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
) {
|
|
return this.income.readPosition(request.user.sub, uid);
|
|
}
|
|
|
|
@Get(':uid/coupons')
|
|
@ApiOkResponse({ type: BondCouponsResourceDto })
|
|
coupons(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.income.coupons(request.user.sub, uid, query.sync === 'observe');
|
|
}
|
|
}
|