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:
Me
2022-12-14 08:59:00 +01:00
parent 3a6729b9a3
commit 6eaf28d4d8
3 changed files with 20 additions and 16 deletions

View File

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

View File

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

View File

@@ -41,7 +41,6 @@
});
const fetchAllUsers = async() => {
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
.then( x => x.json() );
@@ -56,16 +55,6 @@
console.log({...myFriends})
};
let cherif;
const fetchAFriend = async() => {
cherif = await fetch('http://transcendance:8080/api/v2/network/myfriends/chbadad')
.then( x => x.json() );
console.log('got Cherif ')
console.log(cherif)
// console.log({...cherif})
};
const fetchRequestsMade = async() => {
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
.then( x => x.json() );
@@ -108,9 +97,9 @@
const areWeFriends = async(aUsername) => {
console.log("Are We Friends?")
friendshipStatusFull = undefined;
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
.then( x => x.json());
};
const viewAUser = async(aUsername) => {
@@ -127,7 +116,6 @@
};
const acceptFriendRequest = async(relationshipId) => {
console.log('accept friend request')
friendshipFetch = undefined;
@@ -135,15 +123,17 @@
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/accept`, {
method: "PATCH"})
.then( x => x.json());
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
await areWeFriends(usernameBeingViewed);
};
const unfriend = async(relationshipId) => {
console.log('Unfriend')
friendshipFetch = undefined;
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}`, {
method: "DELETE"})
.then( x => x.json());
await areWeFriends(usernameBeingViewed);
};