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 f49ad6f7..4573b9e7 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts @@ -68,7 +68,7 @@ export class FriendshipController { @Patch('myfriends/:relationshipId/accept') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) - updateAccept(@Param('relationshipId') relationshipId: string, @Req() req) { + updateAccept(@Param('relationshipId') relationshipId: number, @Req() req) { const user : User = req.user; return this.friendshipService.acceptFriendship(relationshipId, user); } @@ -76,7 +76,7 @@ export class FriendshipController { @Patch('myfriends/:relationshipId/decline') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) - updateDecline(@Param('relationshipId') relationshipId: string, @Req() req) { + updateDecline(@Param('relationshipId') relationshipId: number, @Req() req) { const user : User = req.user; return this.friendshipService.declineFriendship(relationshipId, user); } @@ -84,7 +84,7 @@ export class FriendshipController { @Patch('myfriends/:relationshipId/block') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) - updateBlock(@Param('relationshipId') relationshipId: string, @Req() req) { + updateBlock(@Param('relationshipId') relationshipId: number, @Req() req) { const user : User = req.user; return this.friendshipService.blockFriendship(relationshipId, user); } @@ -93,7 +93,7 @@ export class FriendshipController { @Delete('myfriends/:relationshipId') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) - remove(@Param('relationshipId') relationshipId: string, @Req() req) { + remove(@Param('relationshipId') relationshipId: number, @Req() req) { const user : User = req.user; console.log('deleting a friendship') return this.friendshipService.removeFriendship(relationshipId, user); 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 69030939..f80a318f 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts @@ -96,7 +96,7 @@ export class FriendshipService { } async findOneBlocked(friendshipId: number, userId: number) { - const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderId: userId, status: FriendshipStatus.BLOCKED } }); + const friendship = await this.friendshipRepository.findOneBy({ id: friendshipId, senderId: userId, status: FriendshipStatus.BLOCKED }); if (!friendship) throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND); return friendship; @@ -214,8 +214,8 @@ export class FriendshipService { return partialFriendship; } - async acceptFriendship(relationshipId: string, user: User) { - const relation = await this.friendshipRepository.findOneBy({id: +relationshipId }); + async acceptFriendship(relationshipId: number, user: User) { + const relation = await this.friendshipRepository.findOneBy({id: relationshipId }); // console.log('.service accept friendship') // console.log({...relation}) if (!relation) @@ -238,15 +238,15 @@ export class FriendshipService { return partialFriendship; } - async declineFriendship(relationshipId: string, user: User) { - const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} ); - if (!relation[0]) + async declineFriendship(relationshipId: number, user: User) { + const relation = await this.friendshipRepository.findOneBy({id: relationshipId }); + if (!relation) throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND); - if (relation[0].sender.id === user.id) { + if (relation.senderId === user.id) { throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND); } - relation[0].status = FriendshipStatus.DECLINED; - const savedFriendship = this.friendshipRepository.save(relation[0]); + relation.status = FriendshipStatus.DECLINED; + const savedFriendship = this.friendshipRepository.save(relation); const partialFriendship : Partial = { id : (await savedFriendship).id, date : (await savedFriendship).date, @@ -258,8 +258,8 @@ export class FriendshipService { return partialFriendship } - async blockFriendship(relationshipId: string, user: User) { - let relation = await this.friendshipRepository.find({id: +relationshipId }); + async blockFriendship(relationshipId: number, user: User) { + let relation = await this.friendshipRepository.findOneBy({id: relationshipId }); if (!relation) throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND); @@ -295,10 +295,10 @@ export class FriendshipService { } } - async removeFriendship(relationshipId: string, user : User) { + async removeFriendship(relationshipId: number, user : User) { // const friendship = await this.friendshipRepository.findOneBy({ id: +relationshipId }); // once again we need find() not findOneBy() so once again have to grab first elem of an array - const friendship = await this.friendshipRepository.find({id: +relationshipId }); + const friendship = await this.friendshipRepository.findOneBy({id: relationshipId }); console.log('deleting a friendship .service') console.log({...friendship}) console.log('who is the user') diff --git a/srcs/requirements/nestjs/api_back/src/users/users.controller.ts b/srcs/requirements/nestjs/api_back/src/users/users.controller.ts index 01617b9d..ee484a20 100644 --- a/srcs/requirements/nestjs/api_back/src/users/users.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/users/users.controller.ts @@ -40,23 +40,24 @@ export class UsersController { * car un utilisateur est crée à la première connexion avec l'Oauth de 42. */ + // actually fucking useless now... // similar to @Get('myfriends/:friendUsername') but doesn't return a friendship just returns the user profile // GET http://transcendance:8080/user?username=NomDuUser - @UseGuards(AuthenticateGuard) - @UseGuards(TwoFactorGuard) - @Get() - findOne(@Query('id') toFindId: number, @Req() req) { - if (toFindId === undefined) { - console.log("Backend Getting current user"); - return this.usersService.findOne(req.user.id); - } else { - const user : User = req.user; - console.log('we have a query: ' + toFindId) - return this.usersService.findOneById(user.id, toFindId); - } - } + // @UseGuards(AuthenticateGuard) + // @UseGuards(TwoFactorGuard) + // @Get() + // findOne(@Query('id') toFindId: number, @Req() req) { + // if (toFindId === undefined) { + // console.log("Backend Getting current user"); + // return this.usersService.findOne(req.user.id); + // } else { + // const user : User = req.user; + // console.log('we have a query: ' + toFindId) + // return this.usersService.findOneById(user.id, toFindId); + // } + // } - // GET http://transcendance:8080/user?username=NomDuUser + // GET http://transcendance:8080/user @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) @Get()