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 | 9x 9x 9x 9x 9x 9x 9x 9x 7x 9x 3x | import { Controller, Post, Body, HttpCode, HttpStatus } from '@nestjs/common';
import { AuthService } from './auth.service';
import { RegisterUserDto } from './dto/register-user.dto';
import { LoginUserDto } from './dto/login-user.dto';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
@ApiTags('Auth')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('register')
@ApiOperation({ summary: 'Register a new user' })
@ApiBody({
type: RegisterUserDto,
description: 'Details of the user to register',
})
@ApiResponse({ status: 201, description: 'User registered successfully' })
@ApiResponse({ status: 409, description: 'User already exists' })
@ApiResponse({ status: 400, description: 'Body is missing params' })
@HttpCode(HttpStatus.CREATED)
async register(
@Body() registerUserDto: RegisterUserDto,
): Promise<{ message: string }> {
return await this.authService.register(registerUserDto);
}
@Post('login')
@ApiOperation({ summary: 'Login a user' })
@ApiBody({ type: LoginUserDto, description: 'User login details' })
@ApiResponse({ status: 200, description: 'Login successful' })
@ApiResponse({ status: 404, description: 'User not found' })
@HttpCode(HttpStatus.OK)
login(@Body() loginDto: LoginUserDto) {
return this.authService.loginUser(loginDto.email, loginDto.password);
}
}
|