From aa171bd84405ca84a12ac2b42e86d1a1954c036c Mon Sep 17 00:00:00 2001 From: batche Date: Tue, 13 Dec 2022 17:25:00 +0100 Subject: [PATCH] ajout de deux fonctions afin de trouver une relation amicale ou non via le username de ladite relation --- .../src/friendship/friendship.controller.ts | 8 +++++++ .../src/friendship/friendship.service.ts | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) 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')