From 8d6cf9e5e9cc852f855b2e009e214b5df5a1a24c Mon Sep 17 00:00:00 2001 From: Tulupov Date: Sat, 27 Jan 2024 23:37:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D0=BD=D0=B8=D1=82=D1=8C=20=D0=B8=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7=D0=B1=D0=B0=D0=BD=D0=B8=D1=82=D1=8C=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BD=D1=8B=D0=BC=D0=B8=20endpoint'=D0=B0=D0=BC=D0=B8,=20?= =?UTF-8?q?=D1=85=D0=B7=20=D0=BD=D0=B0=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA?= =?UTF-8?q?=D0=BE=20=D1=8D=D1=82=D0=BE=20=D0=BD=D0=B0=D0=B4=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/libs/database/user.entity.ts | 3 ++ backend/src/modules/user/user.controller.ts | 11 +++++- backend/src/modules/user/user.service.ts | 37 +++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/backend/libs/database/user.entity.ts b/backend/libs/database/user.entity.ts index 48317eb..7b16bf7 100644 --- a/backend/libs/database/user.entity.ts +++ b/backend/libs/database/user.entity.ts @@ -11,4 +11,7 @@ export class User { @Column({ nullable: true }) public user_name: string; + + @Column({ nullable: false , default: false}) + public banned: boolean; } diff --git a/backend/src/modules/user/user.controller.ts b/backend/src/modules/user/user.controller.ts index 7e8266f..33e5aab 100644 --- a/backend/src/modules/user/user.controller.ts +++ b/backend/src/modules/user/user.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Post, Put, Param } from '@nestjs/common'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { IGetUser } from './user.dto'; import { UserService } from './user.service'; @@ -15,4 +15,13 @@ export class UserController { async getUser(@Body() data: IGetUser) { return await this.userService.getUser(data); } + @Put('ban/:id') + async banUser(@Param('id') id: string) { + return await this.userService.banUser(id); + } + @Put('deBan/:id') + async deBanUser(@Param('id') id: string) { + return await this.userService.deBanUser(id); + } + } diff --git a/backend/src/modules/user/user.service.ts b/backend/src/modules/user/user.service.ts index 6854cbe..5d3a18c 100644 --- a/backend/src/modules/user/user.service.ts +++ b/backend/src/modules/user/user.service.ts @@ -24,4 +24,41 @@ export class UserService { this.logger.log(`[user.getUser] ${JSON.stringify({ error })}`); } } + async banUser(id: string){ + try { + this.logger.debug(`[user.banUser] id: ${JSON.stringify(id)}`); + let user = await this.userRepository.findOne({ + where: { id: id }, + }); + if(user){ + user.banned = true; + await this.userRepository.save(user); + return user; + } + + user = await this.userRepository.save({ id: id, banned: true }); + return user; + } catch (error) { + this.logger.log(`[user.banUser] ${JSON.stringify({ error })}`); + } + } + + async deBanUser(id: string){ + try { + this.logger.debug(`[user.deBanUser] id: ${JSON.stringify(id)}`); + let user = await this.userRepository.findOne({ + where: { id: id }, + }); + if(user){ + user.banned = false; + await this.userRepository.save(user); + return user; + } + + user = await this.userRepository.save({ id: id, banned: false }); + return user; + } catch (error) { + this.logger.log(`[user.deBanUser] ${JSON.stringify({ error })}`); + } + } }