fixed some stuff in the Friendship backend, but had to cut some corners, it's kinda gross, will fix later, better flow to frontend friendship page, most stuff works, still a few kinks to work out

This commit is contained in:
Me
2022-12-16 04:14:44 +01:00
parent db02946268
commit de06007d60
3 changed files with 114 additions and 48 deletions

View File

@@ -41,6 +41,33 @@
});
/* TMP for Testing */
let cherifFetch;
const fetchCherif = async() => {
cherifFetch = await fetch('http://transcendance:8080/api/v2/network/myfriends/chbadad')
.then( x => x.json() );
console.log('Cherif Fetched ')
console.log({...cherifFetch})
};
let ericFetch;
const fetchEric = async() => {
ericFetch = await fetch('http://transcendance:8080/api/v2/network/myfriends/erlazo')
.then( x => x.json() );
console.log('Eric Fetched ')
console.log({...ericFetch})
};
let tmpTest;
const testBack = async(relationshipId) => {
console.log('test back request')
tmpTest = undefined;
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/test
tmpTest = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/test`)
.then( x => x.json());
};
/* End of Tests */
const fetchAllUsers = async() => {
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
.then( x => x.json() );
@@ -69,22 +96,6 @@
console.log({...requestsRecieved})
};
let cherifFetch;
const fetchCherif = async() => {
cherifFetch = await fetch('http://transcendance:8080/api/v2/network/myfriends/chbadad')
.then( x => x.json() );
console.log('Cherif Fetched ')
console.log({...cherifFetch})
};
let ericFetch;
const fetchEric = async() => {
ericFetch = await fetch('http://transcendance:8080/api/v2/network/myfriends/erlazo')
.then( x => x.json() );
console.log('Eric Fetched ')
console.log({...ericFetch})
};
let sentFriendRequest;
const sendFriendRequest = async(potentialFriendUsername) => {
set.friendUsername = '';
@@ -134,15 +145,6 @@
};
let tmpTest;
const testBack = async(relationshipId) => {
console.log('test back request')
tmpTest = undefined;
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/test
tmpTest = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/test`)
.then( x => x.json());
};
const acceptFriendRequest = async(relationshipId) => {
console.log('accept friend request')
@@ -157,6 +159,20 @@
await areWeFriends(usernameBeingViewed);
};
const declineFriendRequest = async(relationshipId) => {
console.log('decline friend request')
friendshipFetch = undefined;
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/decline
friendshipFetch = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${relationshipId}/decline`, {
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...
console.log('declined friend request, now response')
console.log({...friendshipFetch})
await areWeFriends(usernameBeingViewed);
};
const unfriend = async(relationshipId) => {
console.log('Unfriend')
friendshipFetch = undefined;
@@ -252,10 +268,18 @@
{:else}
<!-- <Button type="secondary" on:click={() => acceptFriendRequest(usernameBeingViewed)}>Unfriend</Button> -->
<Button type="secondary" on:click={() => acceptFriendRequest(friendshipStatusFull.id)}>Accept Friend Request</Button>
<Button on:click={() => declineFriendRequest(friendshipStatusFull.id)}>Decline Friend Request</Button>
{/if}
{:else if friendshipStatusFull.status === 'A'}
<div class="tile">You are Friends</div>
<Button on:click={() => unfriend(friendshipStatusFull.id)}>Unfriend</Button>
{:else if friendshipStatusFull.status === 'D'}
{#if friendshipStatusFull.senderUsername === user.username}
<div class="tile">Your friend request was denied, hang in there bud.</div>
{:else}
<div class="tile">You declined the friend request but you could still change your mind</div>
<Button on:click={() => acceptFriendRequest(friendshipStatusFull.id)}>acceptFriendRequest</Button>
{/if}
{/if}
{:else}
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>