working on accepting friend requests, have to muck about with the DB, i have to learn how to use .find()
This commit is contained in:
@@ -78,7 +78,7 @@ export class FriendshipController {
|
||||
updateAccept(@Param('relationshipId') relationshipId: string, @Req() req)
|
||||
{
|
||||
const user : User = req.user;
|
||||
console.log('accepting a friendship')
|
||||
console.log('accepting a friendship BBBBBBBBBBBBBBBBBBBBBBB')
|
||||
return this.friendshipService.acceptFriendship(relationshipId, user);
|
||||
}
|
||||
|
||||
|
||||
@@ -167,9 +167,20 @@ export class FriendshipService {
|
||||
}
|
||||
|
||||
async acceptFriendship(relationshipId: string, user: User) {
|
||||
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
||||
// const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
||||
// ok gotta swap out hte findOneBy for a find, recall what you did in the Nest.js tutorial
|
||||
// const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
||||
// const relation = await this.friendshipRepository.find({where: {id: +relationshipId } });
|
||||
// const relation = await this.friendshipRepository.findOneBy({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
|
||||
const relation = await this.friendshipRepository.findOne({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
|
||||
|
||||
console.log('.service accept friendship')
|
||||
console.log({...relation})
|
||||
if (!relation)
|
||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
||||
// console.log(relation.sender)
|
||||
// ok so you can't query sender cuz it's not a column in the entity, not sure how you access it then...
|
||||
// if (relation.sender.id === user.id) {
|
||||
if (relation.sender.id === user.id) {
|
||||
throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
@@ -181,6 +192,9 @@ export class FriendshipService {
|
||||
receiverUsername: (await savedFriendship).receiverUsername,
|
||||
status : (await savedFriendship).status
|
||||
}
|
||||
console.log('.service accept friendship END')
|
||||
console.log({...partialFriendship})
|
||||
|
||||
return partialFriendship;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user