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 })}`); + } + } }