@@ -30,26 +30,29 @@ import {
3030} from './dto/password-reset.dto' ;
3131import { Enable2FADto , TwoFADto , Verify2FASetupDto } from './dto/2fa.dto' ;
3232import { JwtAuthGuard } from './guards/jwt-auth.guard' ;
33+ import { RolesGuard } from './guards/roles.guard' ;
3334import type { JwtPayload } from './guards/jwt-auth.guard' ;
3435import { CurrentUser } from './decorators/current-user.decorator' ;
3536import { Public } from './decorators/public.decorator' ;
3637import { ApiAuthErrorResponses } from '../common/decorators/swagger-error-responses.decorator' ;
38+ import { Roles } from '../identity/roles/decorators/roles.decorator' ;
39+ import { UserRole } from '../identity/roles/enums/user-role.enum' ;
3740
38- @ApiTags ( 'identity/ auth' )
39- @UseGuards ( JwtAuthGuard )
40- @Controller ( 'identity/ auth' )
41+ @ApiTags ( 'auth' )
42+ @UseGuards ( JwtAuthGuard , RolesGuard )
43+ @Controller ( 'auth' )
4144export class AuthController {
4245 constructor ( private readonly authService : AuthService ) { }
4346
4447 // ─── Registration & Activation ─────────────────────────────────────────────
4548
4649 @Public ( )
47- @Post ( 'register ' )
50+ @Post ( 'signup ' )
4851 @HttpCode ( HttpStatus . CREATED )
4952 @ApiOperation ( { summary : 'Register a new user account' } )
5053 @ApiResponse ( { status : 201 , description : 'Registration successful' } )
5154 @ApiAuthErrorResponses ( )
52- register ( @Body ( ) dto : RegisterDto , @Req ( ) req : Request ) {
55+ signup ( @Body ( ) dto : RegisterDto , @Req ( ) req : Request ) {
5356 const correlationId =
5457 ( req . headers [ 'x-correlation-id' ] as string ) ||
5558 ( req . headers [ 'x-request-id' ] as string ) ;
@@ -104,13 +107,13 @@ export class AuthController {
104107 // ─── Token Refresh ─────────────────────────────────────────────────────────
105108
106109 @Public ( )
107- @Post ( 'token/ refresh' )
110+ @Post ( 'refresh' )
108111 @HttpCode ( HttpStatus . OK )
109112 @ApiOperation ( {
110113 summary : 'Rotate refresh token and obtain new access + refresh tokens' ,
111114 } )
112115 @ApiResponse ( { status : 200 , description : 'Tokens refreshed' } )
113- refreshToken ( @Body ( ) dto : RefreshTokenDto ) {
116+ refresh ( @Body ( ) dto : RefreshTokenDto ) {
114117 return this . authService . refreshTokens ( dto ) ;
115118 }
116119
@@ -210,4 +213,41 @@ export class AuthController {
210213 disable2FA ( @CurrentUser ( ) user : JwtPayload , @Body ( ) dto : TwoFADto ) {
211214 return this . authService . disable2FA ( user . sub , dto ) ;
212215 }
216+
217+ // ─── Admin Endpoints ───────────────────────────────────────────────────────
218+
219+ @Get ( 'admin/users' )
220+ @Roles ( UserRole . ADMIN , UserRole . SUPER_ADMIN )
221+ @ApiBearerAuth ( )
222+ @ApiOperation ( { summary : 'List all users (admin only)' } )
223+ @ApiResponse ( { status : 200 , description : 'List of all users' } )
224+ listAllUsers ( @CurrentUser ( ) user : JwtPayload ) {
225+ return this . authService . listAllUsers ( ) ;
226+ }
227+
228+ @Post ( 'admin/users/:userId/roles' )
229+ @Roles ( UserRole . ADMIN , UserRole . SUPER_ADMIN )
230+ @ApiBearerAuth ( )
231+ @ApiOperation ( { summary : 'Assign roles to a user (admin only)' } )
232+ @ApiResponse ( { status : 200 , description : 'Roles assigned successfully' } )
233+ assignUserRole (
234+ @CurrentUser ( ) user : JwtPayload ,
235+ @Param ( 'userId' ) userId : string ,
236+ @Body ( ) body : { roles : UserRole [ ] } ,
237+ ) {
238+ return this . authService . assignUserRoles ( userId , body . roles ) ;
239+ }
240+
241+ @Delete ( 'admin/users/:userId/roles' )
242+ @Roles ( UserRole . ADMIN , UserRole . SUPER_ADMIN )
243+ @ApiBearerAuth ( )
244+ @ApiOperation ( { summary : 'Revoke roles from a user (admin only)' } )
245+ @ApiResponse ( { status : 200 , description : 'Roles revoked successfully' } )
246+ revokeUserRole (
247+ @CurrentUser ( ) user : JwtPayload ,
248+ @Param ( 'userId' ) userId : string ,
249+ @Body ( ) body : { roles : UserRole [ ] } ,
250+ ) {
251+ return this . authService . revokeUserRoles ( userId , body . roles ) ;
252+ }
213253}
0 commit comments