Можно забанить и разбанить разными endpoint'ами, хз насколько это надо

This commit is contained in:
Tulupov
2024-01-27 23:37:49 +03:00
parent db67834cfd
commit 8d6cf9e5e9
3 changed files with 50 additions and 1 deletions

View File

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