ajout de deux fonctions afin de trouver une relation amicale ou non via le username de ladite relation
This commit is contained in:
@@ -30,6 +30,14 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findOneFriend(relationshipId, user.username);
|
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 http://transcendance:8080/api/v2/network/blocked
|
||||||
@Get('blocked')
|
@Get('blocked')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ export class FriendshipService {
|
|||||||
return friendship;
|
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) {
|
async findOneBlocked(friendshipId: string, username: string) {
|
||||||
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.BLOCKED } });
|
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.BLOCKED } });
|
||||||
if (!friendship)
|
if (!friendship)
|
||||||
@@ -30,6 +41,16 @@ export class FriendshipService {
|
|||||||
return friendship;
|
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) {
|
async findAllFriends(username: string) {
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
|
|||||||
Reference in New Issue
Block a user