82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import type { Request } from 'express';
|
|
|
|
import { Controller, Get, Param, 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 {
|
|
IncomeAnalyticsQueryDto,
|
|
IncomeAnalyticsResourceDto,
|
|
IncomeSummaryResourceDto,
|
|
} from './income-analytics.dto';
|
|
import { IncomeAnalyticsService } from './income-analytics.service';
|
|
|
|
@ApiTags('brokerage-accounts')
|
|
@ApiProblemResponses()
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('brokerage-accounts')
|
|
export class IncomeAnalyticsController {
|
|
constructor(private readonly income: IncomeAnalyticsService) {}
|
|
|
|
@Get('all/income-summary')
|
|
@ApiOkResponse({ type: IncomeSummaryResourceDto })
|
|
allSummary(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.income.summary(
|
|
request.user.sub,
|
|
'all',
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get('all/income-analytics')
|
|
@ApiOkResponse({ type: IncomeAnalyticsResourceDto })
|
|
allAnalytics(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Query() query: IncomeAnalyticsQueryDto,
|
|
) {
|
|
return this.income.analytics(
|
|
request.user.sub,
|
|
'all',
|
|
query.from,
|
|
query.to,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get(':accountId/income-summary')
|
|
@ApiOkResponse({ type: IncomeSummaryResourceDto })
|
|
summary(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('accountId') accountId: string,
|
|
@Query() query: InvestmentReadQueryDto,
|
|
) {
|
|
return this.income.summary(
|
|
request.user.sub,
|
|
accountId,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
|
|
@Get(':accountId/income-analytics')
|
|
@ApiOkResponse({ type: IncomeAnalyticsResourceDto })
|
|
analytics(
|
|
@Req() request: Request & { user: AccessPayload },
|
|
@Param('accountId') accountId: string,
|
|
@Query() query: IncomeAnalyticsQueryDto,
|
|
) {
|
|
return this.income.analytics(
|
|
request.user.sub,
|
|
accountId,
|
|
query.from,
|
|
query.to,
|
|
query.sync === 'observe',
|
|
);
|
|
}
|
|
}
|