mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
deBan => unBan
This commit is contained in:
@@ -19,9 +19,9 @@ export class UserController {
|
||||
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);
|
||||
@Put('unBan/:id')
|
||||
async unBanUser(@Param('id') id: string) {
|
||||
return await this.userService.unBanUser(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from 'libs/database/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -43,22 +43,20 @@ export class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
async deBanUser(id: string){
|
||||
async unBanUser(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;
|
||||
if (!user){
|
||||
throw new HttpException('No user with this id', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
user = await this.userRepository.save({ id: id, banned: false });
|
||||
return user;
|
||||
} catch (error) {
|
||||
this.logger.log(`[user.deBanUser] ${JSON.stringify({ error })}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user