102 lines
2.8 KiB
TypeScript
102 lines
2.8 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Query,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
|
import type { Request } from 'express';
|
|
import { AccessPayload } from '../auth/auth.types';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { ApiProblemResponses } from '../common/decorators/api-safe-error-response.decorator';
|
|
import { BondService } from './bond.service';
|
|
import {
|
|
BondCandlesDto,
|
|
BondMetricsDto,
|
|
BondCandlesQueryDto,
|
|
BondCouponsDto,
|
|
BondDto,
|
|
BondTickerParamsDto,
|
|
BondPositionDto,
|
|
BondQuoteDto,
|
|
BondSearchQueryDto,
|
|
BondSearchResultDto,
|
|
} from './bond.dto';
|
|
|
|
@ApiTags('bonds')
|
|
@ApiProblemResponses()
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('bonds')
|
|
export class BondController {
|
|
constructor(private readonly bonds: BondService) {}
|
|
@Get(':uid/metrics')
|
|
@ApiOkResponse({ type: BondMetricsDto })
|
|
metrics(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('uid', new ParseUUIDPipe()) uid: string,
|
|
) {
|
|
return this.bonds.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.bonds.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.bonds.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.bonds.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.bonds.coupons(request.user.sub, uid);
|
|
}
|
|
}
|