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:
Me
2022-12-24 23:20:59 +01:00
parent 5cd5ffc24c
commit 2b5f8a9667
3 changed files with 32 additions and 31 deletions

View File

@@ -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);

View File

@@ -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<Friendship> = {
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')

View File

@@ -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()