deBan => unBan

This commit is contained in:
Tulupov
2024-01-28 20:02:11 +03:00
parent 8d6cf9e5e9
commit 8ecef2ee50
2 changed files with 8 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}