29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { Controller, Get, Query, Req, UnauthorizedException, Inject } from '@nestjs/common';
|
|
import { ApiTags, ApiResponse, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
|
import { DashboardService } from './DashboardService';
|
|
import { DashboardOverviewDTO } from './dtos/DashboardOverviewDTO';
|
|
|
|
type AuthenticatedRequest = {
|
|
user?: { userId: string };
|
|
};
|
|
|
|
@ApiTags('dashboard')
|
|
@Controller('dashboard')
|
|
export class DashboardController {
|
|
constructor(@Inject(DashboardService) private readonly dashboardService: DashboardService) {}
|
|
|
|
@Get('overview')
|
|
@ApiOperation({ summary: 'Get dashboard overview' })
|
|
@ApiQuery({ name: 'driverId', description: 'Driver ID' })
|
|
@ApiResponse({ status: 200, description: 'Dashboard overview', type: DashboardOverviewDTO })
|
|
async getDashboardOverview(
|
|
@Query('driverId') _driverId: string,
|
|
@Req() req: AuthenticatedRequest,
|
|
): Promise<DashboardOverviewDTO> {
|
|
const userId = req.user?.userId;
|
|
if (!userId) {
|
|
throw new UnauthorizedException('Unauthorized');
|
|
}
|
|
return this.dashboardService.getDashboardOverview(userId);
|
|
}
|
|
} |