Changements amitiés

This commit is contained in:
batche
2022-12-11 15:30:30 +01:00
parent db1e269e2e
commit a9460fb41c
7 changed files with 200 additions and 155 deletions

View File

@@ -1,11 +1,10 @@
import { IsEnum, IsString } 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 {
@IsString() @IsString()
readonly requesterUsername: string; @IsNotEmpty()
@IsString() readonly receiverUsername: string;
readonly addresseeUsername: string;
@IsEnum(FriendshipStatus) @IsEnum(FriendshipStatus)
readonly status: FriendshipStatus; readonly status: FriendshipStatus;
} }

View File

@@ -17,13 +17,17 @@ export class Friendship {
@CreateDateColumn() @CreateDateColumn()
date : Date; date : Date;
@Column()
@ManyToOne(type => User, user => user.username) @ManyToOne(type => User, user => user.username)
requesterUsername: string; sender: User;
@ManyToOne(type => User, user => user.username)
receiver: User;
@Column() @Column()
@ManyToOne(type => User, user => user.username) senderUsername : string;
addresseeUsername: string;
@Column()
receiverUsername : string;
@Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED}) @Column({ type: 'enum', enum: FriendshipStatus, default: FriendshipStatus.REQUESTED})
status: FriendshipStatus; status: FriendshipStatus;

View File

@@ -12,59 +12,20 @@ export class FriendshipController {
@Get('myfriends') @Get('myfriends')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
findEmpty(@Query('username') username: string, @Req() req) { findEmpty(@Req() req) {
const user = req.user; const user = req.user;
if (username === undefined) { return this.friendshipService.findAllFriends(user.id);
console.log("WHAT IS UP MY GUYS IT IS YOUR BOI THAT IDIOT YOU HATE 11111");
return this.friendshipService.findAllFriends(user.id);
} else {
}
} }
// GET http://transcendance:8080/api/v2/network/myfriends/relationshipId // GET http://transcendance:8080/api/v2/network/myfriends/relationshipId
@Get('myfriends/:relationshipId') @Get('myfriend/:relationshipId')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
findOneFriend(@Param('relationshipId') relationshipId: string, @Req() req) { findOneFriend(@Param('relationshipId') relationshipId: string, @Req() req) {
const user = req.user; const user = req.user;
return this.friendshipService.findOneFriend(relationshipId, user.id); return this.friendshipService.findOneFriend(relationshipId, user.username);
} }
// POST http://transcendance:8080/api/v2/network/myfriends
@Post('myfriends')
@HttpCode(HttpStatus.CREATED)
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
const user = req.user;
console.log(`User id: ${user.id}\nUser name: ${createFriendshipDto.requesterUsername}\nStatus: ${createFriendshipDto.status}`);
if (user.username === createFriendshipDto.requesterUsername)
return this.friendshipService.create(createFriendshipDto, user);
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
}
// PATCH http://transcendance:8080/api/v2/network/myfriends/relationshipId?status=A
@Patch('myfriends/:relationshipId')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
update(@Param('relationshipId') relationshipId: string, @Query('status') status : string, @Req() req)
{
const user : User = req.user;
return this.friendshipService.updateFriendship(relationshipId, user, status);
}
// DELETE http://transcendance:8080/api/v2/network/myfriends/relationshipId
@Delete('myfriends/:relationshipId')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
remove(@Param('relationshipId') relationshipId: string) {
return this.friendshipService.removeFriendship(relationshipId);
}
// GET http://transcendance:8080/api/v2/network/blocked // GET http://transcendance:8080/api/v2/network/blocked
@Get('blocked') @Get('blocked')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@@ -74,15 +35,69 @@ export class FriendshipController {
return this.friendshipService.findAllBlockedFriends(user.username); return this.friendshipService.findAllBlockedFriends(user.username);
} }
@Get('blocked/:relationshipId')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
findOneBlocked(@Param('relationshipId') relationshipId: string, @Req() req) {
const user = req.user;
return this.friendshipService.findOneBlocked(relationshipId, user.username);
}
// POST http://transcendance:8080/api/v2/network/myfriends
@Post('myfriends')
@HttpCode(HttpStatus.CREATED)
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
const user = req.user;
if (user.username !== createFriendshipDto.receiverUsername)
return this.friendshipService.create(createFriendshipDto, user);
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
}
// PATCH http://transcendance:8080/api/v2/network/myfriends/relationshipId/accept
@Patch('myfriends/:relationshipId/accept')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
updateAccept(@Param('relationshipId') relationshipId: string, @Req() req)
{
const user : User = req.user;
return this.friendshipService.acceptFriendship(relationshipId, user);
}
@Patch('myfriends/:relationshipId/decline')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
updateDecline(@Param('relationshipId') relationshipId: string, @Req() req)
{
const user : User = req.user;
return this.friendshipService.declineFriendship(relationshipId, user);
}
@Patch('myfriends/:relationshipId/block')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
updateBlock(@Param('relationshipId') relationshipId: string, @Req() req)
{
const user : User = req.user;
return this.friendshipService.blockFriendship(relationshipId, user);
}
// DELETE http://transcendance:8080/api/v2/network/myfriends/relationshipId
@Delete(':relationshipId')
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
remove(@Param('relationshipId') relationshipId: string, @Req() req) {
const user : User = req.user;
return this.friendshipService.removeFriendship(relationshipId, user);
}
// GET http://transcendance:8080/api/v2/network/pending // GET http://transcendance:8080/api/v2/network/pending
@Get('pending') @Get('pending')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
findAllPendantFriendshipRequested(@Req() req) { findAllPendantFriendshipRequested(@Req() req) {
const user = req.user; const user = req.user;
// console.log("WHAT IS UP MY GUYS IT IS YOUR BOI THAT IDIOT YOU HATE Pending 33333");
return this.friendshipService.findAllPendantRequestsForFriendship(user.id); return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
} }

View File

@@ -17,23 +17,16 @@ export class FriendshipService {
async findOneFriend(friendshipId: string, username: string) { async findOneFriend(friendshipId: string, username: string) {
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, requesterUsername: username, status: FriendshipStatus.ACCEPTED } }); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.ACCEPTED } });
if (!friendship) if (!friendship)
throw new HttpException(`The requested friend not found.`, HttpStatus.NOT_FOUND); throw new HttpException(`The requested friend not found.`, HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
// async findOneFriendByUsername(friendUsername: string, username: string) { async findOneBlocked(friendshipId: string, username: string) {
// const friendship = await this.friendshipRepository.find({ where: { friendUsername: +friendshipId, requesterUsername: username, status: FriendshipStatus.ACCEPTED } }); const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.BLOCKED } });
// if (!friendship)
// throw new HttpException(`The requested friend not found.`, HttpStatus.NOT_FOUND);
// return friendship;
// }
async findOneBlocked(friendshipId: string) {
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, status: FriendshipStatus.BLOCKED } });
if (!friendship) if (!friendship)
throw new HttpException(`The requested user not found.`, HttpStatus.NOT_FOUND); throw new HttpException(`The requested blocked not found.`, HttpStatus.NOT_FOUND);
return friendship; return friendship;
} }
@@ -41,8 +34,8 @@ export class FriendshipService {
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED }) .where('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
.andWhere('friendship.addresseeUsername = :addressee', { addressee: username }) .andWhere('friendship.receiverUsername = :addressee', { addressee: username })
.orWhere('friendship.requesterUsername = :requester', { requester: username }) .orWhere('friendship.senderUsername = :requester', { requester: username })
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
.getMany(); .getMany();
for (const friend of friendship) for (const friend of friendship)
@@ -51,49 +44,53 @@ export class FriendshipService {
} }
async findAllBlockedFriends(username: string) { async findAllBlockedFriends(username: string) {
return await this.friendshipRepository const friendships : Friendship[] = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.where('friendship.requesterUsername = :requestee', { requestee: username }) .where('friendship.senderUsername = :requestee', { requestee: username })
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
.getMany(); .getMany();
let partialFriendship : Partial<Friendship>[] = [];
for (const friendship of friendships) {
partialFriendship.push({id: friendship.id, date: friendship.date, senderUsername: friendship.senderUsername, receiverUsername: friendship.receiverUsername, status: friendship.status});
}
return partialFriendship;
} }
async findAllPendantRequestsForFriendship(username: string) { async findAllPendantRequestsForFriendship(username: string) {
return await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.where('friendship.requesterUsername = :requestee', { requestee: username }) .where('friendship.senderUsername = :requestee', { requestee: username })
.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;
} }
async findAllReceivedRequestsForFriendship(username: string) { async findAllReceivedRequestsForFriendship(username: string) {
return await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.where('friendship.addresseeUsername = :addressee', { addressee: username }) .where('friendship.receiverUsername = :addressee', { addressee: username })
.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;
} }
//GROS CHANTIER
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
const addressee = await this.userRepository.findOneBy({username: createFriendshipDto.addresseeUsername});
console.log('made it to create friendship from friendship controller') async create(createFriendshipDto: CreateFriendshipDto, creator : User) : Promise <Partial<Friendship>> {
console.log("DTO : \n")
if (!addressee) console.log({...createFriendshipDto})
const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername});
if (!receiver)
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND); throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
console.log('Addressee ID: ' + addressee.id + ' Username: ' + addressee.username)
console.log('Creator ID: ' + creator.id + ' Username: ' + creator.username)
if (creator.id === addressee.id)
throw new HttpException(`You can't add yourself.`, HttpStatus.FORBIDDEN);
console.log('test 1')
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED) if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND); throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
console.log('test 2') const friendship = await this.friendshipRepository.findOneBy({ sender: creator, receiver: receiver });
const friendship = await this.friendshipRepository.findOneBy({ requesterUsername: createFriendshipDto.requesterUsername, addresseeUsername: createFriendshipDto.addresseeUsername });
console.log('test 3')
if (friendship) { if (friendship) {
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED) if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK); throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
@@ -104,57 +101,95 @@ export class FriendshipService {
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED) else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
throw new HttpException(`The request has been declined.`, HttpStatus.OK); throw new HttpException(`The request has been declined.`, HttpStatus.OK);
} }
console.log('test 7') const newFriendship = new Friendship();
newFriendship.sender = creator;
const newFriendship = this.friendshipRepository.create(createFriendshipDto); newFriendship.senderUsername = creator.username;
console.log('test 8, New Friendship: ') newFriendship.receiver = receiver;
console.log({...newFriendship}) newFriendship.receiverUsername = receiver.username;
newFriendship.status = createFriendshipDto.status;
const tmp = this.friendshipRepository.save(newFriendship); const savedFriendship = this.friendshipRepository.save(newFriendship);
console.log('tmp: ') const partialFriendship : Partial<Friendship> = {
console.log({...tmp}) id : (await savedFriendship).id,
return tmp; date : (await savedFriendship).date,
// return this.friendshipRepository.save(newFriendship); receiverUsername: (await savedFriendship).receiverUsername,
status : (await savedFriendship).status
}
console.log({...partialFriendship})
return partialFriendship;
} }
async updateFriendship(relationshipId: string, user: User, status: string) { async acceptFriendship(relationshipId: string, user: User) {
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId }); const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
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);
if (+relation.requesterUsername === 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);
} }
if (status === FriendshipStatus.ACCEPTED) relation.status = FriendshipStatus.ACCEPTED;
relation.status = FriendshipStatus.ACCEPTED; const savedFriendship = this.friendshipRepository.save(relation);
else if (status === FriendshipStatus.DECLINED) const partialFriendship : Partial<Friendship> = {
relation.status = FriendshipStatus.DECLINED; id : (await savedFriendship).id,
else if (status === FriendshipStatus.BLOCKED) date : (await savedFriendship).date,
relation.status = FriendshipStatus.BLOCKED; receiverUsername: (await savedFriendship).receiverUsername,
else status : (await savedFriendship).status
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND); }
if (relation.status !== status) return partialFriendship;
throw new HttpException(`We could not update the status.`, HttpStatus.OK);
return this.friendshipRepository.save(relation);
} }
async removeFriendship(relationshipId: string) { async declineFriendship(relationshipId: string, user: User) {
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!relation)
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
if (relation.sender.id === user.id) {
throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
}
relation.status = FriendshipStatus.DECLINED;
const savedFriendship = this.friendshipRepository.save(relation);
const partialFriendship : Partial<Friendship> = {
id : (await savedFriendship).id,
date : (await savedFriendship).date,
receiverUsername: (await savedFriendship).receiverUsername,
status : (await savedFriendship).status
}
return partialFriendship
}
async blockFriendship(relationshipId: string, user: User) {
const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!relation)
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
if (relation.sender.id === user.id) {
throw new HttpException(`You can't accept your own request.`, HttpStatus.NOT_FOUND);
}
relation.status = FriendshipStatus.BLOCKED;
const savedFriendship = this.friendshipRepository.save(relation);
const partialFriendship : Partial<Friendship> = {
id : (await savedFriendship).id,
date : (await savedFriendship).date,
receiverUsername: (await savedFriendship).receiverUsername,
status : (await savedFriendship).status
}
return partialFriendship
}
async removeFriendship(relationshipId: string, user : User) {
const friendship = await this.friendshipRepository.findOneBy({ id: +relationshipId }); const friendship = await this.friendshipRepository.findOneBy({ id: +relationshipId });
if (!friendship) if (!friendship)
throw new HttpException(`Your friend could not be deleted.`, HttpStatus.NOT_FOUND); throw new HttpException(`Your friend could not be deleted.`, HttpStatus.NOT_FOUND);
if (friendship.sender.id !== user.id || friendship.receiver.id !== user.id) {
throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN);
}
return this.friendshipRepository.remove(friendship); return this.friendshipRepository.remove(friendship);
} }
async findIfUserIsBlockedOrHasBlocked(userConnectedId: string, userToCheckId: string) { async findIfUserIsBlockedOrHasBlocked(userConnectedId: string, userToFindId: string) {
console.log("finding if user is blocked") console.log("finding if user is blocked")
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.where('friendship.requesterUsername = :requestee', { requestee: userConnectedId }) .where('friendship.senderUsername = :requestee', { requestee: userConnectedId })
.orWhere('friendship.requesterUsername = :requesteeBis', { requesteeBis: userToCheckId }) .orWhere('friendship.senderUsername = :requesteeBis', { requesteeBis: userToFindId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
.getOne(); .getOne();
console.log("printing friendship")
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

@@ -43,13 +43,11 @@ export class User {
@Column({ nullable: true }) @Column({ nullable: true })
secretTwoFactorAuth: string; secretTwoFactorAuth: string;
@JoinTable() @OneToMany(type => Friendship , (friendship) => friendship.sender)
@OneToMany(type => Friendship , (friendship) => friendship.requesterUsername) sentFriendRequest: Friendship[];
requesterId: Friendship[];
@JoinTable() @OneToMany(type => Friendship , (friendship) => friendship.receiver)
@OneToMany(type => Friendship , (friendship) => friendship.addresseeUsername) receivedFriendRequest: Friendship[];
addresseeId: Friendship[];
@JoinColumn() @JoinColumn()
@OneToOne(() => UserStats, { cascade: true }) @OneToOne(() => UserStats, { cascade: true })

View File

@@ -60,31 +60,26 @@ export class UsersService {
return true; return true;
} }
async findOneByUsername(userConnectedId : string, username: string) { async findOneByUsername(userConnectedId : string, usernameToFind: string) {
const user : User = await this.userRepository.createQueryBuilder('user') const userToFind : User = await this.userRepository.createQueryBuilder('user')
.leftJoinAndSelect('user.stats', 'stats') .leftJoinAndSelect('user.stats', 'stats')
.where('user.username = :username', { username: username }) .where('user.username = :username', { username: usernameToFind })
.getOne(); .getOne();
console.log('USERNAME OF FOUND USER : ' + user.username); console.log('USERNAME OF FOUND USER : ' + userToFind.username);
// console.log({...user}) // console.log({...user})
// you can't do that, you need to do user === undefined // you can't do that, you need to do user === undefined
// if (user === undefined) // if (user === undefined)
if (!user) if (!userToFind)
throw new HttpException(`The user could not be found 1.`,HttpStatus.NOT_FOUND); throw new HttpException(`The user could not be found 1.`,HttpStatus.NOT_FOUND);
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, userToFind.id.toString())) {
let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString())
console.log('printing return of checking if blocked')
console.log(tmp)
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString())) {
console.log('we are blocked in user.service') console.log('we are blocked in user.service')
throw new HttpException(`The user could not be found 2.`,HttpStatus.NOT_FOUND); throw new HttpException(`The user could not be found 2.`,HttpStatus.NOT_FOUND);
} }
const partialUser : Partial<User> = { const partialUser : Partial<User> = {
username: user.username, username: userToFind.username,
image_url: user.image_url, image_url: userToFind.image_url,
status: user.status, status: userToFind.status,
stats: user.stats, stats: userToFind.stats,
}; };
return partialUser; return partialUser;
} }

View File

@@ -15,7 +15,7 @@ Ideas
could be a list of friends and if they're active but i can't see that yet could be a list of friends and if they're active but i can't see that yet
- I click on a thing and it lets me see all the users and i get a button that lets me add them - I click on a thing and it lets me see all the users and i get a button that lets me add them
- would that be like a serachable list of all users? - would that be like a serachable list of all users?
- am i skipping optimization? i mean for now yes, but like - am i skipping optimization? i mean for now yes, but like
@@ -32,12 +32,12 @@ could be a list of friends and if they're active but i can't see that yet
let myFriends; let myFriends;
let requestsMade, requestsRecieved; let requestsMade, requestsRecieved;
let userBeingViewed; let userBeingViewed;
onMount( async() => { onMount( async() => {
// yea no idea what // yea no idea what
// i mean do i fetch user? i will for now // i mean do i fetch user? i will for now
user = await fetch('http://transcendance:8080/api/v2/user') user = await fetch('http://transcendance:8080/api/v2/user')
.then( (x) => x.json() ); .then( (x) => x.json() );
@@ -82,13 +82,13 @@ could be a list of friends and if they're active but i can't see that yet
const displayAllFriends = async() => { const displayAllFriends = async() => {
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends') myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
.then( x => x.json() ); .then( x => x.json() );
// console.log('got all friends ' + allFriends) // console.log('got all friends ' + allFriends)
}; };
const displayRequestsMade = async() => { const displayRequestsMade = 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() );
// console.log('got requests made ' + requestsMade) // console.log('got requests made ' + requestsMade)
}; };
@@ -110,8 +110,7 @@ could be a list of friends and if they're active but i can't see that yet
method : "POST", method : "POST",
headers: { 'Content-Type': 'application/json'}, headers: { 'Content-Type': 'application/json'},
body: JSON.stringify({ body: JSON.stringify({
"requesterUsername": user.username, "receiverUsername": set.friendUsername,
"addresseeUsername": set.friendUsername,
"status": "R" "status": "R"
}) })
}) })
@@ -131,7 +130,7 @@ could be a list of friends and if they're active but i can't see that yet
}; };
const blockAUser = async(friendshipId) => { const blockAUser = async(friendshipId) => {
}; };
@@ -146,7 +145,7 @@ could be a list of friends and if they're active but i can't see that yet
{#if allUsers === undefined} {#if allUsers === undefined}
<div class="error">Failed to load all users</div> <div class="error">Failed to load all users</div>
{:else} {:else}
<!-- problem, i can't use user.id since Cherif doesn't want to expost that to the front... <!-- problem, i can't use user.id since Cherif doesn't want to expost that to the front...
is there something else i could use? --> is there something else i could use? -->
<!-- add a thing so it doesn't display the current user just all the other users --> <!-- add a thing so it doesn't display the current user just all the other users -->
@@ -196,7 +195,7 @@ could be a list of friends and if they're active but i can't see that yet
<DisplayAUser aUsername={userBeingViewed.username}/> <DisplayAUser aUsername={userBeingViewed.username}/>
<Button type="secondary" on:click={() => sendFriendRequest(userBeingViewed.username)}>Add Friend</Button> <Button type="secondary" on:click={() => sendFriendRequest(userBeingViewed.username)}>Add Friend</Button>
{:catch} {:catch}
<p>No user to view yet</p> <p>No user to view yet</p>
{/await} --> {/await} -->
@@ -227,7 +226,7 @@ could be a list of friends and if they're active but i can't see that yet
{/each} {/each}
{/if} --> {/if} -->
<!-- <br> <br> --> <!-- <br> <br> -->
<!-- here i want to list all the requests you and have an accept and a decline button --> <!-- here i want to list all the requests you and have an accept and a decline button -->
@@ -291,4 +290,4 @@ could be a list of friends and if they're active but i can't see that yet
font-weight: bold; font-weight: bold;
color: red; color: red;
} }
</style> </style>