feat: Introduce admin user management API with user listing, retrieval, account activation/deactivation, and case-insensitive role validation.
This commit is contained in:
parent
5c6c13c261
commit
a59b144ebf
6 changed files with 228 additions and 3 deletions
31
Backend/src/controllers/UsermanagementController.ts
Normal file
31
Backend/src/controllers/UsermanagementController.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Get, Body, Post, Route, Tags, SuccessResponse, Response, Example, Controller, Security, Request, Put,Path } from 'tsoa';
|
||||
import { UserManagementService } from '../services/usermanagement.service';
|
||||
import { ValidationError } from '../middleware/errorHandler';
|
||||
import { ListUsersResponse, GetUserResponse, ActivateAccountResponse } from '../types/usersmanagement.types';
|
||||
import { getUserByIdValidator } from '../validators/usermanagement.validator';
|
||||
|
||||
@Route('api/admin/usermanagement')
|
||||
@Tags('Usermanagement')
|
||||
export class UserManagementController {
|
||||
|
||||
private userManagementService = new UserManagementService();
|
||||
|
||||
@Get('users')
|
||||
@Security('jwt' , ['admin'])
|
||||
@SuccessResponse('200', 'Users fetched successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async listUsers(): Promise<ListUsersResponse> {
|
||||
return await this.userManagementService.listUsers();
|
||||
}
|
||||
|
||||
@Get('users/{id}')
|
||||
@Security('jwt' , ['admin'])
|
||||
@SuccessResponse('200', 'User fetched successfully')
|
||||
@Response('401', 'Invalid or expired token')
|
||||
public async getUserById(@Path() id: number): Promise<GetUserResponse> {
|
||||
const { error, value } = getUserByIdValidator.validate({ id });
|
||||
if (error) throw new ValidationError(error.details[0].message);
|
||||
return await this.userManagementService.getUserById(value.id);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue