32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|