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)
|
updateAccept(@Param('relationshipId') relationshipId: string, @Req() req)
|
||||||
{
|
{
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
console.log('accepting a friendship')
|
console.log('accepting a friendship BBBBBBBBBBBBBBBBBBBBBBB')
|
||||||
return this.friendshipService.acceptFriendship(relationshipId, user);
|
return this.friendshipService.acceptFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,9 +167,20 @@ export class FriendshipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async acceptFriendship(relationshipId: string, user: User) {
|
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)
|
if (!relation)
|
||||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
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) {
|
if (relation.sender.id === 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);
|
||||||
}
|
}
|
||||||
@@ -181,6 +192,9 @@ export class FriendshipService {
|
|||||||
receiverUsername: (await savedFriendship).receiverUsername,
|
receiverUsername: (await savedFriendship).receiverUsername,
|
||||||
status : (await savedFriendship).status
|
status : (await savedFriendship).status
|
||||||
}
|
}
|
||||||
|
console.log('.service accept friendship END')
|
||||||
|
console.log({...partialFriendship})
|
||||||
|
|
||||||
return partialFriendship;
|
return partialFriendship;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const fetchAllUsers = async() => {
|
const fetchAllUsers = async() => {
|
||||||
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
@@ -56,16 +55,6 @@
|
|||||||
console.log({...myFriends})
|
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() => {
|
const fetchRequestsMade = async() => {
|
||||||
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
@@ -108,9 +97,9 @@
|
|||||||
|
|
||||||
const areWeFriends = async(aUsername) => {
|
const areWeFriends = async(aUsername) => {
|
||||||
console.log("Are We Friends?")
|
console.log("Are We Friends?")
|
||||||
|
friendshipStatusFull = undefined;
|
||||||
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
|
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
|
||||||
.then( x => x.json());
|
.then( x => x.json());
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewAUser = async(aUsername) => {
|
const viewAUser = async(aUsername) => {
|
||||||
@@ -127,7 +116,6 @@
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const acceptFriendRequest = async(relationshipId) => {
|
const acceptFriendRequest = async(relationshipId) => {
|
||||||
console.log('accept friend request')
|
console.log('accept friend request')
|
||||||
friendshipFetch = undefined;
|
friendshipFetch = undefined;
|
||||||
@@ -135,15 +123,17 @@
|
|||||||
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/accept`, {
|
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/accept`, {
|
||||||
method: "PATCH"})
|
method: "PATCH"})
|
||||||
.then( x => x.json());
|
.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) => {
|
const unfriend = async(relationshipId) => {
|
||||||
console.log('Unfriend')
|
console.log('Unfriend')
|
||||||
friendshipFetch = undefined;
|
friendshipFetch = undefined;
|
||||||
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
|
|
||||||
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}`, {
|
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}`, {
|
||||||
method: "DELETE"})
|
method: "DELETE"})
|
||||||
.then( x => x.json());
|
.then( x => x.json());
|
||||||
|
await areWeFriends(usernameBeingViewed);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user