36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { Controller, Get, Query, ValidationPipe } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiOkResponse } from '@nestjs/swagger';
|
|
import { SecuritiesService } from './securities.service';
|
|
import { ScreenerService } from './screener.service';
|
|
import { SearchQueryDto, SecurityType } from './dto/search-query.dto';
|
|
import { ScreenerQueryDto } from './dto/screener-query.dto';
|
|
import { ScreenerResponseDto } from './dto/screener-response.dto';
|
|
|
|
@ApiTags('Securities')
|
|
@Controller('securities')
|
|
export class SecuritiesController {
|
|
constructor(
|
|
private readonly securitiesService: SecuritiesService,
|
|
private readonly screenerService: ScreenerService,
|
|
) {}
|
|
|
|
@Get('search')
|
|
@ApiOperation({ summary: 'Поиск по инструментам' })
|
|
async search(@Query(ValidationPipe) query: SearchQueryDto) {
|
|
const results = await this.securitiesService.search(
|
|
query.q,
|
|
query.type || SecurityType.ALL,
|
|
query.limit || 20,
|
|
);
|
|
return { data: results, meta: { cachedAt: null, fromCache: false } };
|
|
}
|
|
|
|
@Get('screener')
|
|
@ApiOperation({ summary: 'Фильтр ценных бумаг по параметрам' })
|
|
@ApiOkResponse({ type: ScreenerResponseDto })
|
|
async screener(@Query(ValidationPipe) query: ScreenerQueryDto) {
|
|
const result = await this.screenerService.screen(query);
|
|
return { data: result, meta: { cachedAt: null, fromCache: false } };
|
|
}
|
|
}
|