amélioration des requêtes d'amitié, on peut maintenant directement bloquer une personne.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { IsEnum, IsInt, IsNumber, IsOptional, IsPositive, IsString } from 'class-validator';
|
import { IsEnum, IsString } from 'class-validator';
|
||||||
import { FriendshipStatus } from '../entities/friendship.entity';
|
import { FriendshipStatus } from '../entities/friendship.entity';
|
||||||
|
|
||||||
export class CreateFriendshipDto {
|
export class CreateFriendshipDto {
|
||||||
@@ -7,6 +7,5 @@ export class CreateFriendshipDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
readonly addresseeId: string;
|
readonly addresseeId: string;
|
||||||
@IsEnum(FriendshipStatus)
|
@IsEnum(FriendshipStatus)
|
||||||
@IsOptional()
|
|
||||||
readonly status: FriendshipStatus;
|
readonly status: FriendshipStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { FriendshipService } from './friendship.service';
|
|||||||
export class FriendshipController {
|
export class FriendshipController {
|
||||||
constructor(private readonly friendshipService: FriendshipService) { }
|
constructor(private readonly friendshipService: FriendshipService) { }
|
||||||
|
|
||||||
// GET http://127.0.0.1:3000/api/v2/network/myfriends
|
// GET http://transcendance:8080/api/v2/network/myfriends
|
||||||
@Get('myfriends')
|
@Get('myfriends')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -17,7 +17,7 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findAllFriends(user.id);
|
return this.friendshipService.findAllFriends(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId
|
// GET http://transcendance:8080/api/v2/network/myfriends/relationshipId
|
||||||
@Get('myfriends/:relationshipId')
|
@Get('myfriends/:relationshipId')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -26,20 +26,20 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findOneFriend(relationshipId, user.id);
|
return this.friendshipService.findOneFriend(relationshipId, user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST http://127.0.0.1:3000/api/v2/network/myfriends
|
// POST http://transcendance:8080/api/v2/network/myfriends
|
||||||
@Post('myfriends')
|
@Post('myfriends')
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
console.log(`User id: ${user.id}\n Friend id: ${createFriendshipDto.requesterId}`);
|
console.log(`User id: ${user.id}\nFriend id: ${createFriendshipDto.requesterId}\nStatus: ${createFriendshipDto.status}`);
|
||||||
if (user.id === +createFriendshipDto.requesterId)
|
if (user.id === +createFriendshipDto.requesterId)
|
||||||
return this.friendshipService.create(createFriendshipDto, user);
|
return this.friendshipService.create(createFriendshipDto, user);
|
||||||
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
|
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PATCH http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId?status=A
|
// PATCH http://transcendance:8080/api/v2/network/myfriends/relationshipId?status=A
|
||||||
@Patch('myfriends/:relationshipId')
|
@Patch('myfriends/:relationshipId')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -49,7 +49,7 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.updateFriendship(relationshipId, user, status);
|
return this.friendshipService.updateFriendship(relationshipId, user, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE http://127.0.0.1:3000/api/v2/network/myfriends/relationshipId
|
// DELETE http://transcendance:8080/api/v2/network/myfriends/relationshipId
|
||||||
@Delete('myfriends/:relationshipId')
|
@Delete('myfriends/:relationshipId')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -58,7 +58,7 @@ export class FriendshipController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GET http://127.0.0.1:3000/api/v2/network/blocked
|
// GET http://transcendance:8080/api/v2/network/blocked
|
||||||
@Get('blocked')
|
@Get('blocked')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -67,7 +67,7 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findAllBlockedFriends(user.id);
|
return this.friendshipService.findAllBlockedFriends(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET http://127.0.0.1:3000/api/v2/network/pending
|
// GET http://transcendance:8080/api/v2/network/pending
|
||||||
@Get('pending')
|
@Get('pending')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -76,7 +76,7 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
|
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET http://127.0.0.1:3000/api/v2/network/received
|
// GET http://transcendance:8080/api/v2/network/received
|
||||||
@Get('received')
|
@Get('received')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ export class FriendshipService {
|
|||||||
if (!addressee)
|
if (!addressee)
|
||||||
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
||||||
if (creator.id === addressee.id)
|
if (creator.id === addressee.id)
|
||||||
throw new HttpException(`You can't add yourself.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`You can't add yourself.`, HttpStatus.FORBIDDEN);
|
||||||
|
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
|
||||||
|
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
||||||
const friendship = await this.friendshipRepository.findOneBy({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId });
|
const friendship = await this.friendshipRepository.findOneBy({ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId });
|
||||||
if (friendship) {
|
if (friendship) {
|
||||||
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
|
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
|
||||||
@@ -86,8 +88,7 @@ export class FriendshipService {
|
|||||||
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
|
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
|
||||||
throw new HttpException(`The request has been declined.`, HttpStatus.OK);
|
throw new HttpException(`The request has been declined.`, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
const newFriendship = this.friendshipRepository.create(
|
const newFriendship = this.friendshipRepository.create(createFriendshipDto);
|
||||||
{ requesterId: createFriendshipDto.requesterId, addresseeId: createFriendshipDto.addresseeId, status: FriendshipStatus.REQUESTED });
|
|
||||||
return this.friendshipRepository.save(newFriendship);
|
return this.friendshipRepository.save(newFriendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,9 +96,9 @@ export class FriendshipService {
|
|||||||
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
||||||
if (!relation)
|
if (!relation)
|
||||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
||||||
// if (+relation.requesterId === user.id) {
|
if (+relation.requesterId === user.id) {
|
||||||
// throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
|
||||||
// }
|
}
|
||||||
if (status === FriendshipStatus.ACCEPTED)
|
if (status === FriendshipStatus.ACCEPTED)
|
||||||
relation.status = FriendshipStatus.ACCEPTED;
|
relation.status = FriendshipStatus.ACCEPTED;
|
||||||
else if (status === FriendshipStatus.DECLINED)
|
else if (status === FriendshipStatus.DECLINED)
|
||||||
|
|||||||
Reference in New Issue
Block a user