forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.controller.ts
More file actions
55 lines (52 loc) · 2.04 KB
/
Copy pathdashboard.controller.ts
File metadata and controls
55 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
Controller,
Get,
Query,
Req,
UseGuards,
ParseIntPipe,
DefaultValuePipe,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { DashboardService } from './dashboard.service';
import { DashboardSummaryDto, DashboardActivityDto } from './dto/dashboard.dto';
import { ApiErrorResponseDto } from '../common/dto/api-error-response.dto';
@ApiTags('Dashboard')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('dashboard')
export class DashboardController {
constructor(private readonly dashboardService: DashboardService) {}
@Get('summary')
@ApiOperation({ summary: 'Get dashboard summary cards for the authenticated user' })
@ApiOkResponse({ description: 'Summary stats', type: DashboardSummaryDto })
@ApiUnauthorizedResponse({ description: 'Missing or invalid authentication', type: ApiErrorResponseDto })
async getSummary(@Req() req: any): Promise<DashboardSummaryDto> {
return this.dashboardService.getSummary(req.user.id);
}
@Get('activity')
@ApiOperation({ summary: 'Get recent activity feed for the authenticated user' })
@ApiQuery({ name: 'page', required: false, type: Number, example: 1 })
@ApiQuery({ name: 'limit', required: false, type: Number, example: 20 })
@ApiOkResponse({ description: 'Paginated activity list', type: DashboardActivityDto })
@ApiBadRequestResponse({ description: 'Invalid pagination parameters', type: ApiErrorResponseDto })
@ApiUnauthorizedResponse({ description: 'Missing or invalid authentication', type: ApiErrorResponseDto })
async getActivity(
@Req() req: any,
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
@Query('limit', new DefaultValuePipe(20), ParseIntPipe) limit: number,
): Promise<DashboardActivityDto> {
const safeLimit = Math.min(limit, 100);
return this.dashboardService.getActivity(req.user.id, page, safeLimit);
}
}