Spaces:
Running
Running
| import { | |
| Controller, | |
| Post, | |
| Get, | |
| Patch, | |
| Body, | |
| HttpCode, | |
| HttpStatus, | |
| UseGuards, | |
| Ip, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiBearerAuth, | |
| ApiOperation, | |
| ApiResponse, | |
| } from '@nestjs/swagger'; | |
| import { AuthService } from './auth.service'; | |
| import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'; | |
| import { Public } from '../../common/decorators/public.decorator'; | |
| import { CurrentUser } from '../../common/decorators/current-user.decorator'; | |
| import { | |
| LoginDto, | |
| RegisterDto, | |
| RefreshTokenDto, | |
| UpdateProfileDto, | |
| ChangePasswordDto, | |
| } from './dto'; | |
| ('Auth') | |
| ('auth') | |
| export class AuthController { | |
| constructor(private authService: AuthService) {} | |
| () | |
| ('register') | |
| (HttpStatus.CREATED) | |
| ({ summary: 'Register new account' }) | |
| ({ status: 201, description: 'User registered successfully' }) | |
| ({ status: 409, description: 'Email already exists' }) | |
| async register(() dto: RegisterDto): Promise<any> { | |
| return this.authService.register(dto); | |
| } | |
| () | |
| ('login') | |
| (HttpStatus.OK) | |
| ({ summary: 'Login with email and password' }) | |
| ({ status: 200, description: 'Login successful' }) | |
| ({ status: 401, description: 'Invalid credentials' }) | |
| async login(() dto: LoginDto, () ip: string): Promise<any> { | |
| return this.authService.login(dto, ip); | |
| } | |
| ('logout') | |
| (HttpStatus.OK) | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: 'Logout current user' }) | |
| ({ status: 200, description: 'Logout successful' }) | |
| async logout( | |
| ('userId') userId: string, | |
| ('token') token: string, | |
| ): Promise<any> { | |
| return this.authService.logout(userId, token); | |
| } | |
| () | |
| ('refresh') | |
| (HttpStatus.OK) | |
| ({ summary: 'Refresh access token' }) | |
| ({ status: 200, description: 'Token refreshed successfully' }) | |
| ({ status: 401, description: 'Invalid refresh token' }) | |
| async refreshToken(() dto: RefreshTokenDto): Promise<any> { | |
| return this.authService.refreshToken(dto); | |
| } | |
| ('profile') | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: 'Get current user profile' }) | |
| ({ status: 200, description: 'Profile retrieved successfully' }) | |
| async getProfile(('userId') userId: string): Promise<any> { | |
| return this.authService.getProfile(userId); | |
| } | |
| ('profile') | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: 'Update user profile' }) | |
| ({ status: 200, description: 'Profile updated successfully' }) | |
| async updateProfile( | |
| ('userId') userId: string, | |
| () dto: UpdateProfileDto, | |
| ): Promise<any> { | |
| return this.authService.updateProfile(userId, dto); | |
| } | |
| ('change-password') | |
| (HttpStatus.OK) | |
| (JwtAuthGuard) | |
| () | |
| ({ summary: 'Change password' }) | |
| ({ status: 200, description: 'Password changed successfully' }) | |
| ({ status: 400, description: 'Invalid current password' }) | |
| async changePassword( | |
| ('userId') userId: string, | |
| () dto: ChangePasswordDto, | |
| ): Promise<any> { | |
| return this.authService.changePassword(userId, dto); | |
| } | |
| () | |
| ('forgot-password') | |
| (HttpStatus.OK) | |
| ({ summary: 'Request password reset' }) | |
| ({ status: 200, description: 'Password reset email sent' }) | |
| async forgotPassword(('email') email: string): Promise<any> { | |
| return this.authService.forgotPassword(email); | |
| } | |
| } | |