diff --git a/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts b/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts index 8500df60..e45e11f6 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts @@ -30,6 +30,14 @@ export class FriendshipController { return this.friendshipService.findOneFriend(relationshipId, user.username); } + @Get('myfriends/:friendUsername') + @UseGuards(AuthenticateGuard) + @UseGuards(TwoFactorGuard) + findOneRelationByUsername(@Param('friendUsername') friendUsername : string, @Req() req) { + const user = req.user; + return this.friendshipService.findOneFriendByUsername(friendUsername, user.username); + } + // GET http://transcendance:8080/api/v2/network/blocked @Get('blocked') @UseGuards(AuthenticateGuard) diff --git a/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts b/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts index cee750cd..159b4b49 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts @@ -23,6 +23,17 @@ export class FriendshipService { return friendship; } + async findOneFriendByUsername(friendUsername : string, username : string) { + const friendship = await this.friendshipRepository + .createQueryBuilder('friendship') + .where('friendship.senderUsername = : username', {username : username}) + .andWhere('friendship.receiverUsername = : friendUsername', {friendUsername : friendUsername}) + .andWhere('friendship.status = : status ', {status : FriendshipStatus.REQUESTED}) + .orWhere('friendship.status = : status ', {status : FriendshipStatus.ACCEPTED}) + .getOne() + return friendship; + } + async findOneBlocked(friendshipId: string, username: string) { const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.BLOCKED } }); if (!friendship) @@ -30,6 +41,16 @@ export class FriendshipService { return friendship; } + async findOneBlockedByUsername(blockedUsername : string, username : string) { + const friendship = await this.friendshipRepository + .createQueryBuilder('friendship') + .where('friendship.senderUsername = : username', {username : username}) + .andWhere('friendship.receiverUsername = : friendUsername', {friendUsername : blockedUsername}) + .andWhere('friendship.status = : status ', {status : FriendshipStatus.BLOCKED}) + .getOne() + return friendship; + } + async findAllFriends(username: string) { const friendship = await this.friendshipRepository .createQueryBuilder('friendship')