Get all banned users

This commit is contained in:
2024-02-09 23:00:52 +03:00
parent 45af61f8e0
commit 8520002444
2 changed files with 17 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { Body, Controller, Param, Post, Put } from '@nestjs/common'; import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { IGetUser } from './user.dto'; import { IGetUser } from './user.dto';
import { UserService } from './user.service'; import { UserService } from './user.service';
@@ -31,4 +31,12 @@ export class UserController {
async unBanUser(@Param('id') id: string) { async unBanUser(@Param('id') id: string) {
return await this.userService.unBanUser(id); return await this.userService.unBanUser(id);
} }
@ApiOperation({
description: 'Get all banned users',
})
@Get('banned')
async getBannedUsers() {
return await this.userService.getBannedUsers();
}
} }

View File

@@ -60,7 +60,14 @@ export class UserService {
throw error; throw error;
} }
this.logger.debug(`[user.deBanUser] ${JSON.stringify({ error })}`); this.logger.debug(`[user.deBanUser] ${JSON.stringify({ error })}`);
throw new HttpException(`[user.unBanUser] Error: ${JSON.stringify(error)}`, HttpStatus.BAD_GATEWAY);
async getBannedUsers() {
try {
this.logger.log('[user.getBannedUsers]');
return await this.userRepository.find({ where: { banned: true }, select: { id: true, user_name: true } });
} catch (error) {
this.logger.debug(`[user.getBannedUsers] ${error}`);
throw new HttpException('Error occurred', HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
} }