smal service change

This commit is contained in:
simplonco
2023-01-17 11:52:02 +01:00
parent 61badedd21
commit 0dbe255f26

View File

@@ -347,12 +347,18 @@ export class ChatService {
let relation = await this.findOneRelationshipByUsername(to_block_username, username);
if (relation)
{
let blocked_friendship = await this.friendshipService.blockFriendship(relation.id, user);
await this.friendshipService.blockFriendship(relation.id, user);
}
else
{
const newFriendshipDto = {"receiverUsername": to_block_username, "status": FriendshipStatus.BLOCKED};
await this.friendshipService.create(newFriendshipDto, user);
if (newFriendshipDto)
await this.friendshipService.create(newFriendshipDto, user);
else
{
printCaller(`throw error: error: true, code: 'BLOCK_USER_FAILED', message: 'we couldn't block the user because it was not found'`);
throw new HttpException({ error: true, code: 'BLOCK_USER_FAILED', message: `we couldn't block the user because it was not found` }, HttpStatus.UNAUTHORIZED);
}
}
printCaller("-- out ");
@@ -363,8 +369,16 @@ export class ChatService {
printCaller("-- in ");
let user = await this.getUserByName(username);
let relation = await this.findOneRelationshipByUsername(to_unblock_username, username);
await this.friendshipService.removeFriendship(relation.id, user);
let relation: SendableFriendship;
if (user)
relation = await this.findOneRelationshipByUsername(to_unblock_username, username);
if (relation)
await this.friendshipService.removeFriendship(relation.id, user);
else
{
printCaller(`throw error: error: true, code: 'REMOVE_USER_FAILED', message: 'we couldn't unblock the user because it was not found'`);
throw new HttpException({ error: true, code: 'REMOVE_USER_FAILED', message: `we couldn't unblock the user because it was not found` }, HttpStatus.UNAUTHORIZED);
}
printCaller("-- out ");
}
@@ -373,9 +387,11 @@ export class ChatService {
{
printCaller("-- in ");
let users: string[] = [];
let friends_users: SendableFriendship[];
let user = await this.getUserByName(username);
let friends_users = await this.friendshipService.findAllBlockedFriends(user.id);
let users: string[];
if (user)
friends_users = await this.friendshipService.findAllBlockedFriends(user.id);
if (friends_users)
users = friends_users.map(user => user.receiverUsername);