2025-10-27 06:41:51 +00:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Header,
|
|
|
|
|
HttpCode,
|
|
|
|
|
Post,
|
|
|
|
|
UseGuards,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import { CreateUserDto, CreateUserDtoResponse } from './dto/create-user.dto';
|
|
|
|
|
import { AuthDto, AuthDtoResponse, UserRole } from './dto/auth.dto';
|
|
|
|
|
import { AuthService } from './auth.service';
|
2025-10-27 07:29:44 +00:00
|
|
|
import { AuthGuard } from './guard/auth.guard';
|
|
|
|
|
import { RolesGuard } from './guard/roles.guard';
|
|
|
|
|
import { Roles } from './decorator/roles.decorator';
|
2025-10-27 06:41:51 +00:00
|
|
|
|
|
|
|
|
@Controller('/auth')
|
|
|
|
|
export class AuthController {
|
|
|
|
|
constructor(private authService: AuthService) {}
|
|
|
|
|
|
|
|
|
|
@Post('/register')
|
|
|
|
|
@Header('Content-Type', 'application/json')
|
|
|
|
|
@HttpCode(201)
|
|
|
|
|
@UseGuards(AuthGuard, RolesGuard)
|
|
|
|
|
@Roles(UserRole.Admin)
|
|
|
|
|
registerUser(@Body() data: CreateUserDto): Promise<CreateUserDtoResponse> {
|
|
|
|
|
return this.authService.registerUser(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/login')
|
|
|
|
|
@Header('Content-Type', 'application/json')
|
|
|
|
|
@HttpCode(200)
|
|
|
|
|
loginUser(@Body() data: AuthDto): Promise<AuthDtoResponse> {
|
|
|
|
|
return this.authService.signIn(data.username, data.password);
|
|
|
|
|
}
|
|
|
|
|
}
|