From 8520002444b79ec22077223d1cd6d1b53661af3f Mon Sep 17 00:00:00 2001 From: Sergey Elpashev Date: Fri, 9 Feb 2024 23:00:52 +0300 Subject: [PATCH] Get all banned users --- backend/src/modules/user/user.controller.ts | 10 +++++++++- backend/src/modules/user/user.service.ts | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/src/modules/user/user.controller.ts b/backend/src/modules/user/user.controller.ts index 364b24a..260e2a1 100644 --- a/backend/src/modules/user/user.controller.ts +++ b/backend/src/modules/user/user.controller.ts @@ -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 { IGetUser } from './user.dto'; import { UserService } from './user.service'; @@ -31,4 +31,12 @@ export class UserController { async unBanUser(@Param('id') id: string) { return await this.userService.unBanUser(id); } + + @ApiOperation({ + description: 'Get all banned users', + }) + @Get('banned') + async getBannedUsers() { + return await this.userService.getBannedUsers(); + } } diff --git a/backend/src/modules/user/user.service.ts b/backend/src/modules/user/user.service.ts index 4d68fb4..96c1ad2 100644 --- a/backend/src/modules/user/user.service.ts +++ b/backend/src/modules/user/user.service.ts @@ -60,7 +60,14 @@ export class UserService { throw 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); } } }