ok the friendship and user refactor is done, there are still a lot of comments but that's fine, it's duct taped together, but it works, time to merge

This commit is contained in:
Me
2023-01-05 11:21:34 +01:00
parent d3be6e5fe8
commit 46090b1e33
10 changed files with 98 additions and 164 deletions

View File

@@ -1,10 +1,7 @@
import { IsEnum, IsNotEmpty, IsString, IsPositive } from 'class-validator'; import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
import { FriendshipStatus } from '../entities/friendship.entity'; import { FriendshipStatus } from '../entities/friendship.entity';
export class CreateFriendshipDto { export class CreateFriendshipDto {
// @IsPositive()
// @Max(1000) ?
// readonly receiverId: number;
@IsNotEmpty() @IsNotEmpty()
@IsString() @IsString()
readonly receiverUsername: string; readonly receiverUsername: string;

View File

@@ -20,23 +20,9 @@ export class Friendship {
@ManyToOne(type => User, user => user.username) @ManyToOne(type => User, user => user.username)
sender: User; sender: User;
// hold on do i want this instead?
// @ManyToOne(type => User, user => user.id)
@ManyToOne(type => User, user => user.username) @ManyToOne(type => User, user => user.username)
receiver: User; receiver: User;
// ok so the username is still here because i think it might be useful for the frontend to have access to it, but really all i need is the ID's
// since i have the ID's do i even need the User ?
// @Column()
// senderUsername : string;
// @Column()
// senderId : number;
// @Column()
// receiverUsername : string;
// @Column()
// receiverId : number;
@Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED}) @Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED})
status: FriendshipStatus; status: FriendshipStatus;
} }

View File

@@ -8,17 +8,6 @@ import { FriendshipService } from './friendship.service';
export class FriendshipController { export class FriendshipController {
constructor(private readonly friendshipService: FriendshipService) { } constructor(private readonly friendshipService: FriendshipService) { }
// GET http://transcendance:8080/api/v2/network/myfriends
// @Get('myfriends')
// @UseGuards(AuthenticateGuard)
// @UseGuards(TwoFactorGuard)
// findEmpty(@Req() req) {
// const user = req.user;
// console.log('GET myfriends')
// return this.friendshipService.findAllFriends(user.id);
// }
// @Query('username') username: string,
// new and improved finder of people // new and improved finder of people
// GET http://transcendance:8080/api/v2/network/myfriends // GET http://transcendance:8080/api/v2/network/myfriends
@@ -32,23 +21,10 @@ export class FriendshipController {
console.log('my friend: ' + otherUsername) console.log('my friend: ' + otherUsername)
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username); return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
} }
// might change this return this.friendshipService.findAllFriendships(user.id);
return this.friendshipService.findAllFriends(user.id); // return this.friendshipService.findAllFriends(user.id);
// return this.friendshipService.findOneRelationshipByUsername(friendUsername, user.username);
} }
// GET http://transcendance:8080/api/v2/network/:friendUsername
// @Get('myfriends/:friendUsername')
// @UseGuards(AuthenticateGuard)
// @UseGuards(TwoFactorGuard)
// findOneRelationByUsername(@Param('friendUsername') friendUsername : string, @Req() req) {
// console.log('GET myfriend')
// console.log(friendUsername);
// const user = req.user;
// return this.friendshipService.findOneRelationshipByUsername(friendUsername, user.username);
// }
// POST http://transcendance:8080/api/v2/network/relations // POST http://transcendance:8080/api/v2/network/relations
@Post('relations') @Post('relations')
@HttpCode(HttpStatus.CREATED) @HttpCode(HttpStatus.CREATED)

View File

@@ -1,6 +1,7 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { User } from 'src/users/entities/user.entity'; import { User } from 'src/users/entities/user.entity';
import { SendableUser } from 'src/users/sendableUsers';
import { Repository, Brackets } from 'typeorm'; import { Repository, Brackets } from 'typeorm';
import { CreateFriendshipDto } from './dto/create-friendship.dto'; import { CreateFriendshipDto } from './dto/create-friendship.dto';
import { Friendship, FriendshipStatus } from './entities/friendship.entity'; import { Friendship, FriendshipStatus } from './entities/friendship.entity';
@@ -30,6 +31,7 @@ export class FriendshipService {
// return ret; // return ret;
// }; // };
//kinda useless but someone else might use it
async findOneRelationshipById(friendId : number, userId : number) { async findOneRelationshipById(friendId : number, userId : number) {
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
@@ -45,16 +47,16 @@ export class FriendshipService {
) )
.orWhere( .orWhere(
new Brackets((subBQb) => { new Brackets((subBQb) => {
subBQb.where('sender.id = :friendId', {friendId : friendId}) subBQb.where('sender.id = :friendId2', {friendId2 : friendId})
.andWhere('receiver.id = :userId', {userId : userId}) .andWhere('receiver.id = :userId2', {userId2 : userId})
}) })
) )
}), }),
) )
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED}) // .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
.getOne() .getOne()
console.log('END Find one friend by username: ') console.log('END Find one friend by ID: ')
console.log({...friendship}) console.log({...friendship})
if (!friendship) { if (!friendship) {
@@ -65,7 +67,6 @@ export class FriendshipService {
return new SendableFriendship(friendship); return new SendableFriendship(friendship);
} }
// basically useless now
async findOneRelationshipByUsername(friendUsername : string, username : string) { async findOneRelationshipByUsername(friendUsername : string, username : string) {
// This seems to work, finding friendships by username but checking the actual users not the friendship // This seems to work, finding friendships by username but checking the actual users not the friendship
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
@@ -82,13 +83,13 @@ export class FriendshipService {
) )
.orWhere( .orWhere(
new Brackets((subBQb) => { new Brackets((subBQb) => {
subBQb.where('sender.username = :friendUsername', {friendUsername : friendUsername}) subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
.andWhere('receiver.username = :username', {username : username}) .andWhere('receiver.username = :username2', {username2 : username})
}) })
) )
}), }),
) )
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED}) // .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
.getOne() .getOne()
console.log('END Find one friend by username: ') console.log('END Find one friend by username: ')
@@ -101,8 +102,9 @@ export class FriendshipService {
return new SendableFriendship(friendship); return new SendableFriendship(friendship);
} }
// lets see what happens here, doing directly receiver.id not LeftJoinAndSelect ... // maybe i should be returning a list of users not a list of friendships
async findAllFriends(userId: number) { // async findAllFriends(userId: number) {
async findAllFriendships(userId: number) {
const friendships = await this.friendshipRepository const friendships = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
@@ -115,13 +117,28 @@ export class FriendshipService {
// for (const friend of friendship) // for (const friend of friendship)
// console.log("FRIENDSHIP : " + friend.status); // console.log("FRIENDSHIP : " + friend.status);
// return friendship; // return friendship;
// return new SendableFriendship(friendship); let sendFrienships: SendableFriendship[] = [];
let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
} }
// return new SendableFriendship(friendship); // return new SendableFriendship(friendship);
console.log('friendship.service my friends:')
console.log({...sendFrienships})
return sendFrienships; return sendFrienships;
// let sendFriends: SendableUser[] = [];
// for (const friendship of friendships) {
// let user: User;
// if (friendship.sender.id !== userId)
// user = friendship.sender;
// else
// user = friendship.receiver;
// sendFriends.push(new SendableUser(user));
// }
// console.log('friendship.service my friends as Users:')
// console.log({...sendFriends})
// return sendFriends;
} }
async findOneBlocked(friendshipId: number, userId: number) { async findOneBlocked(friendshipId: number, userId: number) {
@@ -153,7 +170,6 @@ export class FriendshipService {
if (!friendship) { if (!friendship) {
throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND); throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
} }
// return friendship;
return new SendableFriendship(friendship); return new SendableFriendship(friendship);
} }
@@ -191,16 +207,10 @@ export class FriendshipService {
.where('sender.id = :requestee', { requestee: userId }) .where('sender.id = :requestee', { requestee: userId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
.getMany(); .getMany();
// let partialFriendship : Partial<Friendship>[] = [];
// for (const friend of friendships) {
// console.log("FRIENDSHIP : " + friend);
// partialFriendship.push({id: friend.id, senderUsername: friend.senderUsername, receiverUsername: friend.receiverUsername, status: friend.status});
// }
// console.log("Pendant requests : " + partialFriendship);
// return partialFriendship;
console.log('friendships services pendant friendships:') console.log('friendships services pendant friendships:')
console.log({...friendships}) console.log({...friendships})
// return friendships;
let sendFrienships: SendableFriendship[] = [] let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
@@ -216,14 +226,10 @@ export class FriendshipService {
.where('receiver.id = :addressee', { addressee: userId }) .where('receiver.id = :addressee', { addressee: userId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
.getMany(); .getMany();
// let partialFriendship : Partial<Friendship>[] = [];
// for (const friend of friendship) {
// partialFriendship.push({id: friend.id, senderUsername: friend.senderUsername, receiverUsername: friend.receiverUsername, status: friend.status});
// }
// return partialFriendship;
console.log('friendship service received requests') console.log('friendship service received requests')
console.log({...friendships}) console.log({...friendships})
// return friendships;
let sendFrienships: SendableFriendship[] = [] let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
@@ -239,8 +245,8 @@ export class FriendshipService {
// These throws don't seem to work... // These throws don't seem to work...
const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername}); const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername});
console.log('receiver: ') // console.log('receiver: ')
console.log({...receiver}) // console.log({...receiver})
if (!receiver) if (!receiver)
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND); throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED) if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
@@ -291,10 +297,10 @@ export class FriendshipService {
// } // }
// console.log('friendship.service create friendship, partial friendship') // console.log('friendship.service create friendship, partial friendship')
// console.log({...partialFriendship}) // console.log({...partialFriendship})
console.log('friendship.service create friendship, NEW friendship') // console.log('friendship.service create friendship, NEW friendship')
console.log({...newFriendship}) // console.log({...newFriendship})
console.log('friendship.service create friendship, SAVED friendship') // console.log('friendship.service create friendship, SAVED friendship')
console.log({...savedFriendship}) // console.log({...savedFriendship})
// return partialFriendship; // return partialFriendship;
return new SendableFriendship(savedFriendship); return new SendableFriendship(savedFriendship);
} }
@@ -347,15 +353,6 @@ export class FriendshipService {
} }
relation.status = FriendshipStatus.DECLINED; relation.status = FriendshipStatus.DECLINED;
const savedFriendship = await this.friendshipRepository.save(relation); const savedFriendship = await this.friendshipRepository.save(relation);
// const partialFriendship : Partial<Friendship> = {
// id : (await savedFriendship).id,
// date : (await savedFriendship).date,
// receiverUsername: (await savedFriendship).receiverUsername,
// status : (await savedFriendship).status
// }
// console.log('decline friend request')
// console.log({...partialFriendship})
// return partialFriendship
return new SendableFriendship(savedFriendship); return new SendableFriendship(savedFriendship);
} }
@@ -403,8 +400,6 @@ export class FriendshipService {
} }
async removeFriendship(relationshipId: number, 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 const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
@@ -422,12 +417,10 @@ export class FriendshipService {
} }
console.log('.service deleted a friendship') console.log('.service deleted a friendship')
return this.friendshipRepository.remove(friendship); return this.friendshipRepository.remove(friendship);
// what is the return here? am i getting something right?
} }
// ok for some reason this isn't working...
//i think maybe i should be using ID rather than username...
// async findIfUserIsBlockedOrHasBlocked(userConnectedUsername: string, userToFindUsername: string) {
async findIfUserIsBlockedOrHasBlocked(userConnectedId: number, userToFindId: number) { async findIfUserIsBlockedOrHasBlocked(userConnectedId: number, userToFindId: number) {
console.log("finding if user is blocked") console.log("finding if user is blocked")
console.log('user connected: ' + userConnectedId) console.log('user connected: ' + userConnectedId)
@@ -447,8 +440,8 @@ export class FriendshipService {
) )
.orWhere( .orWhere(
new Brackets((subBQb) => { new Brackets((subBQb) => {
subBQb.where('sender.id = :senderId', {senderId : userToFindId}) subBQb.where('sender.id = :senderId2', {senderId2 : userToFindId})
.andWhere('receiver.id = :receiverId', {receiverUsername : userConnectedId}) .andWhere('receiver.id = :receiverId2', {receiverId2 : userConnectedId})
}) })
) )
}), }),
@@ -457,9 +450,8 @@ export class FriendshipService {
.getOne() .getOne()
console.log('printing friendship queried')
// console.log('printing friendship queried') console.log({...friendship})
// console.log({...friendship})
if (friendship) { if (friendship) {
console.log('we are blocked in friendship.service') console.log('we are blocked in friendship.service')
return true; return true;

View File

@@ -10,9 +10,7 @@ export class SendableFriendship {
id: number; id: number;
date: Date; date: Date;
senderUsername: string; senderUsername: string;
// senderId: number;
receiverUsername: string; receiverUsername: string;
// receiverId: number;
status: FriendshipStatus; status: FriendshipStatus;
// if my constructor is here won't it get sent all over the place too? // if my constructor is here won't it get sent all over the place too?
@@ -20,9 +18,7 @@ export class SendableFriendship {
this.id = friendship.id; this.id = friendship.id;
this.date = friendship.date this.date = friendship.date
this.senderUsername = friendship.sender.username; this.senderUsername = friendship.sender.username;
// this.senderId = friendship.sender.id;
this.receiverUsername = friendship.receiver.username; this.receiverUsername = friendship.receiver.username;
// this.receiverId = friendship.receiver.id;
this.status = friendship.status; this.status = friendship.status;
}; };
} }

View File

@@ -0,0 +1,18 @@
import { User } from "./entities/user.entity";
import { UserStats } from "./entities/userStat.entities";
export class SendableUser {
username: string;
image_url : string;
status: string;
stats: UserStats;
// if my constructor is here won't it get sent all over the place too?
constructor(user: User) {
this.username = user.username;
this.image_url = user.image_url;
this.status = user.status;
this.stats = user.stats;
};
}

View File

@@ -24,11 +24,7 @@ export class UsersController {
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Get('all') @Get('all')
findAll(@Req() req) { findAll(@Req() req) {
// findAll(@Query() paginationquery : PaginationQueryDto, @Req() req) {
//const { limit, offset } = query;
// not convinced i want pagination... i mean maybe for loading and such, we shall see
const user : User = req.user; const user : User = req.user;
// return this.usersService.findAll(paginationquery, user);
return this.usersService.findAll(user); return this.usersService.findAll(user);
} }
@@ -71,7 +67,6 @@ export class UsersController {
return this.usersService.findOne(req.user.username); return this.usersService.findOne(req.user.username);
else else
return this.usersService.findOne(usernameToFind); return this.usersService.findOne(usernameToFind);
// i would rather just use numbers but i'm guessing Cherif uses this all over
} }
// also seems useless... // also seems useless...

View File

@@ -64,49 +64,21 @@ export class UsersService {
return true; return true;
} }
// ok yea this shit makes no fucking sense any more since we're always gonna have the id, this is meant to return someone by username, fuck that
// async findOneById(userId : number, toFindId: number) {
// const userToFind : User = await this.userRepository.createQueryBuilder('user')
// .leftJoinAndSelect('user.stats', 'stats')
// .where('user.id = :toFindId', { toFindId: toFindId })
// .getOne();
// console.log('USERNAME OF FOUND USER : ' + userToFind.username);
// // console.log({...user})
// // you can't do that, you need to do user === undefined
// // if (user === undefined)
// if (!userToFind)
// throw new HttpException(`The user could not be found 1.`,HttpStatus.NOT_FOUND);
// if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, userToFind.id)) {
// console.log('we are blocked in user.service')
// throw new HttpException(`The user could not be found 2.`,HttpStatus.NOT_FOUND);
// }
// const partialUser : Partial<User> = {
// username: userToFind.username,
// image_url: userToFind.image_url,
// status: userToFind.status,
// stats: userToFind.stats,
// };
// return partialUser;
// }
// fuck pagination Query
// async findAll(paginationquery : PaginationQueryDto, currentUser: User) {
async findAll(currentUser: User) { async findAll(currentUser: User) {
// const { limit, offset } = paginationquery;
// const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}, skip: offset, take: limit,}); // const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}, skip: offset, take: limit,});
const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}}); const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}});
let partialUsers : Partial<User>[] = []; let partialUsers : Partial<User>[] = [];
for (const otherUser of otherUsers) { for (const otherUser of otherUsers) {
// console.log('other user: ') console.log('other user: ')
// console.log({...otherUser}) console.log({...otherUser})
// let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(user.username, otherUser.username); let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
// console.log('user.services findIF Blocked... : ') console.log('user.services findIF Blocked... : ')
// console.log(tmp) console.log(tmp)
// if (tmp === false) { if (tmp === false) {
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) { // if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) {
partialUsers.push({id: otherUser.id, username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats}); partialUsers.push({username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats});
} }
} }
console.log('user.services findAll, partialUsers:') console.log('user.services findAll, partialUsers:')

View File

@@ -11,7 +11,7 @@
let user; let user;
let allUsers; let allUsers;
let myFriends; let myFriendships;
let requestsMade, requestsRecieved; let requestsMade, requestsRecieved;
let blockedUsers; let blockedUsers;
let usernameBeingViewed; let usernameBeingViewed;
@@ -45,7 +45,7 @@
const fetchAll = async() => { const fetchAll = async() => {
// no need to await i think it can load in the background // no need to await i think it can load in the background
fetchAllUsers(); fetchAllUsers();
fetchMyFriends(); fetchMyFriendships();
fetchRequestsMade(); fetchRequestsMade();
fetchRequestsReceived(); fetchRequestsReceived();
fetchBlockedUsers(); fetchBlockedUsers();
@@ -59,11 +59,13 @@
console.log({...allUsers}) console.log({...allUsers})
}; };
const fetchMyFriends = async() => { // it's more like fetch friendships
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends') // then i need to extract the users
const fetchMyFriendships = async() => {
myFriendships = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() ); .then( x => x.json() );
console.log('got my friends ') console.log('got my friends ')
console.log({...myFriends}) console.log({...myFriendships})
}; };
const fetchRequestsMade = async() => { const fetchRequestsMade = async() => {
@@ -127,12 +129,11 @@
console.log('Friendship Status Full') console.log('Friendship Status Full')
console.log({...friendshipStatusFull}) console.log({...friendshipStatusFull})
}; };
const acceptFriendRequest = async(relationshipId) => { const acceptFriendRequest = async(relationshipId) => {
console.log('accept friend request') console.log('accept friend request')
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/accept
const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/accept`, { const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/accept`, {
method: "PATCH"}) method: "PATCH"})
.then( x => x.json()); .then( x => x.json());
@@ -147,7 +148,6 @@
const declineFriendRequest = async(relationshipId) => { const declineFriendRequest = async(relationshipId) => {
console.log('decline friend request') console.log('decline friend request')
// PATCH http://transcendance:8080/api/v2/network/myfriends/:relationshipId/decline
const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/decline`, { const resp = await fetch(`http://transcendance:8080/api/v2/network/relations/${relationshipId}/decline`, {
method: "PATCH"}) method: "PATCH"})
.then( x => x.json()); .then( x => x.json());
@@ -173,16 +173,15 @@
activeTabItem = activeTabItem; activeTabItem = activeTabItem;
}; };
const blockANonFriendUser = async(aUser) => { const blockANonFriendUser = async(aUsername) => {
console.log('Block a non friend user, their username') console.log('Block a non friend user, their username')
console.log({...aUser}) console.log(aUsername)
const blockResp = await fetch("http://transcendance:8080/api/v2/network/relations", { const blockResp = await fetch("http://transcendance:8080/api/v2/network/relations", {
method : "POST", method : "POST",
headers: { 'Content-Type': 'application/json'}, headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({ body: JSON.stringify({
"receiverUsername": aUser.username, "receiverUsername": aUsername,
"receiverId": aUser.username,
"status": "B" "status": "B"
}) })
}) })
@@ -222,7 +221,7 @@
if (activeTabItem === 'All Users') { if (activeTabItem === 'All Users') {
await fetchAllUsers(); await fetchAllUsers();
} else if (activeTabItem === 'My Friends') { } else if (activeTabItem === 'My Friends') {
await fetchMyFriends(); await fetchMyFriendships();
} else if (activeTabItem === 'Friend Requests') { } else if (activeTabItem === 'Friend Requests') {
await fetchRequestsReceived(); await fetchRequestsReceived();
} else if (activeTabItem === 'Blocked Users') { } else if (activeTabItem === 'Blocked Users') {
@@ -265,15 +264,18 @@
<div class="status sidebar-item">{aUser.status}</div> <div class="status sidebar-item">{aUser.status}</div>
<br> <br>
{/each} {/each}
{:else if activeTabItem === 'My Friends' && myFriends !== undefined} {:else if activeTabItem === 'My Friends' && myFriendships !== undefined}
<h3>{activeTabItem}</h3> <h3>{activeTabItem}</h3>
{#if Object.keys(myFriends).length === 0} {#if Object.keys(myFriendships).length === 0}
<div class="tip">You don't have any Friends... Yet!</div> <div class="tip">You don't have any Friends... Yet!</div>
{/if} {/if}
<!-- {#each myFriends as aUser (aUser.id)} --> <!-- {#each myFriends as aUser (aUser.id)} -->
{#each myFriends as aUser} {#each myFriendships as aFriendship}
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div> {#if aFriendship.senderUsername !== user.username}
<div class="status sidebar-item">{aUser.status}</div> <div class="sidebar-item" on:click={() => viewAUser(aFriendship.senderUsername)}>{aFriendship.senderUsername}</div>
{:else if aFriendship.receiverUsername !== user.username}
<div class="sidebar-item" on:click={() => viewAUser(aFriendship.receiverUsername)}>{aFriendship.receiverUsername}</div>
{/if}
<br> <br>
{/each} {/each}
{:else if activeTabItem === 'Friend Requests' && requestsRecieved !== undefined} {:else if activeTabItem === 'Friend Requests' && requestsRecieved !== undefined}
@@ -340,7 +342,7 @@
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button> <Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
<Button on:click={() => blockANonFriendUser(usernameBeingViewed)}>Block User</Button> <Button on:click={() => blockANonFriendUser(usernameBeingViewed)}>Block User</Button>
{/if} {/if}
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button> <!-- <Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button> -->
</div> </div>
{:else} {:else}
<div class="placeholder"> <div class="placeholder">

View File

@@ -11,7 +11,7 @@
// console.log('Display aUser username: '+ aUsername) // console.log('Display aUser username: '+ aUsername)
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver // http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`) // user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`) user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
.then( (x) => x.json() ); .then( (x) => x.json() );
// console.log('Display a user: ') // console.log('Display a user: ')
@@ -32,7 +32,7 @@
// console.log('Display Update aUser username: '+ aUsername) // console.log('Display Update aUser username: '+ aUsername)
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver // http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`) // user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`) user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
.then( (x) => x.json() ); .then( (x) => x.json() );
}; };