mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
Можно забанить и разбанить разными endpoint'ами, хз насколько это надо
This commit is contained in:
@@ -11,4 +11,7 @@ export class User {
|
||||
|
||||
@Column({ nullable: true })
|
||||
public user_name: string;
|
||||
|
||||
@Column({ nullable: false , default: false})
|
||||
public banned: boolean;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 })}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user