ok seems like the back is running, have yet to test, but first i need to fix like basically all the front...
This commit is contained in:
@@ -68,7 +68,7 @@ export class FriendshipController {
|
|||||||
@Patch('myfriends/:relationshipId/accept')
|
@Patch('myfriends/:relationshipId/accept')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
updateAccept(@Param('relationshipId') relationshipId: string, @Req() req) {
|
updateAccept(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
return this.friendshipService.acceptFriendship(relationshipId, user);
|
return this.friendshipService.acceptFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ export class FriendshipController {
|
|||||||
@Patch('myfriends/:relationshipId/decline')
|
@Patch('myfriends/:relationshipId/decline')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
updateDecline(@Param('relationshipId') relationshipId: string, @Req() req) {
|
updateDecline(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
return this.friendshipService.declineFriendship(relationshipId, user);
|
return this.friendshipService.declineFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ export class FriendshipController {
|
|||||||
@Patch('myfriends/:relationshipId/block')
|
@Patch('myfriends/:relationshipId/block')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
updateBlock(@Param('relationshipId') relationshipId: string, @Req() req) {
|
updateBlock(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
return this.friendshipService.blockFriendship(relationshipId, user);
|
return this.friendshipService.blockFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ export class FriendshipController {
|
|||||||
@Delete('myfriends/:relationshipId')
|
@Delete('myfriends/:relationshipId')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
remove(@Param('relationshipId') relationshipId: string, @Req() req) {
|
remove(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
console.log('deleting a friendship')
|
console.log('deleting a friendship')
|
||||||
return this.friendshipService.removeFriendship(relationshipId, user);
|
return this.friendshipService.removeFriendship(relationshipId, user);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ export class FriendshipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOneBlocked(friendshipId: number, userId: number) {
|
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)
|
if (!friendship)
|
||||||
throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
|
||||||
return friendship;
|
return friendship;
|
||||||
@@ -214,8 +214,8 @@ export class FriendshipService {
|
|||||||
return partialFriendship;
|
return partialFriendship;
|
||||||
}
|
}
|
||||||
|
|
||||||
async acceptFriendship(relationshipId: string, user: User) {
|
async acceptFriendship(relationshipId: number, user: User) {
|
||||||
const relation = await this.friendshipRepository.findOneBy({id: +relationshipId });
|
const relation = await this.friendshipRepository.findOneBy({id: relationshipId });
|
||||||
// console.log('.service accept friendship')
|
// console.log('.service accept friendship')
|
||||||
// console.log({...relation})
|
// console.log({...relation})
|
||||||
if (!relation)
|
if (!relation)
|
||||||
@@ -238,15 +238,15 @@ export class FriendshipService {
|
|||||||
return partialFriendship;
|
return partialFriendship;
|
||||||
}
|
}
|
||||||
|
|
||||||
async declineFriendship(relationshipId: string, user: User) {
|
async declineFriendship(relationshipId: number, user: User) {
|
||||||
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
const relation = await this.friendshipRepository.findOneBy({id: relationshipId });
|
||||||
if (!relation[0])
|
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[0].sender.id === user.id) {
|
if (relation.senderId === user.id) {
|
||||||
throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
relation[0].status = FriendshipStatus.DECLINED;
|
relation.status = FriendshipStatus.DECLINED;
|
||||||
const savedFriendship = this.friendshipRepository.save(relation[0]);
|
const savedFriendship = this.friendshipRepository.save(relation);
|
||||||
const partialFriendship : Partial<Friendship> = {
|
const partialFriendship : Partial<Friendship> = {
|
||||||
id : (await savedFriendship).id,
|
id : (await savedFriendship).id,
|
||||||
date : (await savedFriendship).date,
|
date : (await savedFriendship).date,
|
||||||
@@ -258,8 +258,8 @@ export class FriendshipService {
|
|||||||
return partialFriendship
|
return partialFriendship
|
||||||
}
|
}
|
||||||
|
|
||||||
async blockFriendship(relationshipId: string, user: User) {
|
async blockFriendship(relationshipId: number, user: User) {
|
||||||
let relation = await this.friendshipRepository.find({id: +relationshipId });
|
let 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);
|
||||||
|
|
||||||
@@ -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 });
|
// 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
|
// 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('deleting a friendship .service')
|
||||||
console.log({...friendship})
|
console.log({...friendship})
|
||||||
console.log('who is the user')
|
console.log('who is the user')
|
||||||
|
|||||||
@@ -40,23 +40,24 @@ export class UsersController {
|
|||||||
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
* 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
|
// similar to @Get('myfriends/:friendUsername') but doesn't return a friendship just returns the user profile
|
||||||
// GET http://transcendance:8080/user?username=NomDuUser
|
// GET http://transcendance:8080/user?username=NomDuUser
|
||||||
@UseGuards(AuthenticateGuard)
|
// @UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
// @UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
// @Get()
|
||||||
findOne(@Query('id') toFindId: number, @Req() req) {
|
// findOne(@Query('id') toFindId: number, @Req() req) {
|
||||||
if (toFindId === undefined) {
|
// if (toFindId === undefined) {
|
||||||
console.log("Backend Getting current user");
|
// console.log("Backend Getting current user");
|
||||||
return this.usersService.findOne(req.user.id);
|
// return this.usersService.findOne(req.user.id);
|
||||||
} else {
|
// } else {
|
||||||
const user : User = req.user;
|
// const user : User = req.user;
|
||||||
console.log('we have a query: ' + toFindId)
|
// console.log('we have a query: ' + toFindId)
|
||||||
return this.usersService.findOneById(user.id, toFindId);
|
// return this.usersService.findOneById(user.id, toFindId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// GET http://transcendance:8080/user?username=NomDuUser
|
// GET http://transcendance:8080/user
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
@Get()
|
||||||
|
|||||||
Reference in New Issue
Block a user