Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import { Controller, Post, Body, HttpCode, HttpStatus, Req, } from '@nestjs/common'; import { AuthService } from './auth.service'; import { RegisterDto, LoginDto, RefreshTokenDto } from './dto/auth.dto'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; @Controller('api/v1/auth') @ApiTags('Auth') export class AuthController { constructor(private readonly authService: AuthService) {} @Post('register') @ApiOperation({ summary: 'Register operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async register(@Body() dto: RegisterDto) { return this.authService.register(dto); } @Post('login') @HttpCode(HttpStatus.OK) @ApiOperation({ summary: 'Login operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async login(@Body() dto: LoginDto) { return this.authService.login(dto); } @Post('refresh') @HttpCode(HttpStatus.OK) @ApiOperation({ summary: 'Refresh token operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async refreshToken(@Body() dto: RefreshTokenDto) { return this.authService.refreshToken(dto); } @Post('logout') @HttpCode(HttpStatus.OK) @ApiOperation({ summary: 'Logout operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async logout(@Req() req: any) { // In production, extract userId from JWT guard const userId = req.user?.id; if (userId) { return this.authService.logout(userId); } return { message: 'Logged out' }; } } |