authentication authorization
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
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(private readonly dashboardService: DashboardService) {}
|
||||
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): Promise<DashboardOverviewDTO> {
|
||||
return this.dashboardService.getDashboardOverview(driverId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user