Merge branch 'master' into hugo
This commit is contained in:
@@ -15,14 +15,13 @@ export class FriendshipController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
findOne(@Query('username') otherUsername: string, @Req() req) {
|
findOne(@Query('username') otherUsername: string, @Req() req) {
|
||||||
console.log('GET myfriends')
|
// console.log('GET myfriends')
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
if (otherUsername !== undefined) {
|
if (otherUsername !== undefined) {
|
||||||
console.log('my friend: ' + otherUsername)
|
// console.log('my friend: ' + otherUsername)
|
||||||
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
|
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
|
||||||
}
|
}
|
||||||
return this.friendshipService.findAllFriendships(user.id);
|
return this.friendshipService.findAllFriendships(user.id);
|
||||||
// return this.friendshipService.findAllFriends(user.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST http://transcendance:8080/api/v2/network/relations
|
// POST http://transcendance:8080/api/v2/network/relations
|
||||||
@@ -31,10 +30,10 @@ export class FriendshipController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
||||||
console.log('friendship.service create')
|
// console.log('friendship.service create')
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
if (user.username !== createFriendshipDto.receiverUsername) {
|
if (user.username !== createFriendshipDto.receiverUsername) {
|
||||||
console.log('friendship.service create have a receiver name')
|
// console.log('friendship.service create have a receiver name')
|
||||||
return this.friendshipService.create(createFriendshipDto, user);
|
return this.friendshipService.create(createFriendshipDto, user);
|
||||||
}
|
}
|
||||||
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
|
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
|
||||||
@@ -73,7 +72,7 @@ export class FriendshipController {
|
|||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
remove(@Param('relationshipId') relationshipId: number, @Req() req) {
|
remove(@Param('relationshipId') relationshipId: number, @Req() req) {
|
||||||
const user : User = req.user;
|
const user : User = req.user;
|
||||||
console.log('deleting a friendship')
|
// console.log('deleting a friendship')
|
||||||
return this.friendshipService.removeFriendship(relationshipId, user);
|
return this.friendshipService.removeFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,21 +99,13 @@ export class FriendshipController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
findBlocked(@Query('relationshipId') relationshipId: number, @Req() req) {
|
findBlocked(@Query('relationshipId') relationshipId: number, @Req() req) {
|
||||||
console.log('friendship.controller fetching blocked users')
|
// console.log('friendship.controller fetching blocked users')
|
||||||
console.log(relationshipId)
|
// console.log(relationshipId)
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
// if (relationshipId === undefined)
|
|
||||||
if (Number.isNaN(relationshipId))
|
if (Number.isNaN(relationshipId))
|
||||||
return this.friendshipService.findAllBlockedFriends(user.id);
|
return this.friendshipService.findAllBlockedFriends(user.id);
|
||||||
else
|
else
|
||||||
return this.friendshipService.findOneBlocked(relationshipId, user.id);
|
return this.friendshipService.findOneBlocked(relationshipId, user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
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 { 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';
|
||||||
@@ -17,20 +19,6 @@ export class FriendshipService {
|
|||||||
private readonly userRepository: Repository<User>,
|
private readonly userRepository: Repository<User>,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|
||||||
// createSendableFriendship(friendship: Friendship): SendableFriendship {
|
|
||||||
// let ret = new SendableFriendship;
|
|
||||||
|
|
||||||
// ret.id = friendship.id;
|
|
||||||
// ret.date = friendship.date
|
|
||||||
// ret.senderUsername = friendship.sender.username;
|
|
||||||
// ret.senderId = friendship.sender.id;
|
|
||||||
// ret.receiverUsername = friendship.receiver.username;
|
|
||||||
// ret.receiverId = friendship.receiver.id;
|
|
||||||
// ret.status = friendship.status;
|
|
||||||
// return ret;
|
|
||||||
// };
|
|
||||||
|
|
||||||
//kinda useless but someone else might use it
|
//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
|
||||||
@@ -49,6 +37,7 @@ export class FriendshipService {
|
|||||||
new Brackets((subBQb) => {
|
new Brackets((subBQb) => {
|
||||||
subBQb.where('sender.id = :friendId2', {friendId2 : friendId})
|
subBQb.where('sender.id = :friendId2', {friendId2 : friendId})
|
||||||
.andWhere('receiver.id = :userId2', {userId2 : userId})
|
.andWhere('receiver.id = :userId2', {userId2 : userId})
|
||||||
|
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@@ -56,14 +45,12 @@ export class FriendshipService {
|
|||||||
// .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
// .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||||
.getOne()
|
.getOne()
|
||||||
|
|
||||||
console.log('END Find one friend by ID: ')
|
// console.log('END Find one friend by ID: ')
|
||||||
console.log({...friendship})
|
// console.log({...friendship})
|
||||||
|
|
||||||
if (!friendship) {
|
if (!friendship) {
|
||||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
// return friendship;
|
|
||||||
// return this.createSendableFriendship(friendship);
|
|
||||||
return new SendableFriendship(friendship);
|
return new SendableFriendship(friendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +72,7 @@ export class FriendshipService {
|
|||||||
new Brackets((subBQb) => {
|
new Brackets((subBQb) => {
|
||||||
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
|
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
|
||||||
.andWhere('receiver.username = :username2', {username2 : username})
|
.andWhere('receiver.username = :username2', {username2 : username})
|
||||||
|
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
@@ -92,18 +80,15 @@ export class FriendshipService {
|
|||||||
// .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: ')
|
||||||
console.log({...friendship})
|
// console.log({...friendship})
|
||||||
|
|
||||||
if (!friendship) {
|
if (!friendship) {
|
||||||
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
// return friendship;
|
|
||||||
return new SendableFriendship(friendship);
|
return new SendableFriendship(friendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe i should be returning a list of users not a list of friendships
|
|
||||||
// async findAllFriends(userId: number) {
|
|
||||||
async findAllFriendships(userId: number) {
|
async findAllFriendships(userId: number) {
|
||||||
const friendships = await this.friendshipRepository
|
const friendships = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
@@ -114,35 +99,17 @@ export class FriendshipService {
|
|||||||
.orWhere('sender.id = :requester', { requester: userId })
|
.orWhere('sender.id = :requester', { requester: userId })
|
||||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
.andWhere('friendship.status = :status', { status: FriendshipStatus.ACCEPTED })
|
||||||
.getMany();
|
.getMany();
|
||||||
// for (const friend of friendship)
|
|
||||||
// console.log("FRIENDSHIP : " + friend.status);
|
|
||||||
// return 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);
|
// console.log('friendship.service my friends:')
|
||||||
console.log('friendship.service my friends:')
|
// console.log({...sendFrienships})
|
||||||
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) {
|
||||||
// const friendship = await this.friendshipRepository.findOneBy({ id: friendshipId, sender.id: userId, status: FriendshipStatus.BLOCKED });
|
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
@@ -153,11 +120,9 @@ export class FriendshipService {
|
|||||||
.getOne();
|
.getOne();
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async findOneBlockedByUsername(blockedUsername : string, userId : number) {
|
async findOneBlockedByUsername(blockedUsername : string, userId : number) {
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
@@ -181,21 +146,20 @@ export class FriendshipService {
|
|||||||
.where('sender.id = :requestee', { requestee: userId })
|
.where('sender.id = :requestee', { requestee: userId })
|
||||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
// let partialFriendship : Partial<Friendship>[] = [];
|
// let partialFriendship : Partial<Friendship>[] = [];
|
||||||
// for (const friendship of friendships) {
|
// for (const friendship of friendships) {
|
||||||
// partialFriendship.push({id: friendship.id, date: friendship.date, senderUsername: friendship.senderUsername, receiverUsername: friendship.receiverUsername, status: friendship.status});
|
// partialFriendship.push({id: friendship.id, date: friendship.date, senderUsername: friendship.senderUsername, receiverUsername: friendship.receiverUsername, status: friendship.status});
|
||||||
// }
|
// }
|
||||||
console.log('friendship.service findAllBlockedFriends, friendships:')
|
// console.log('friendship.service findAllBlockedFriends, friendships:')
|
||||||
console.log({...friendships})
|
// console.log({...friendships})
|
||||||
console.log('friendship.service findAllBlockedFriends, partial friendship:')
|
// console.log('friendship.service findAllBlockedFriends, partial friendship:')
|
||||||
// console.log({...partialFriendship})
|
|
||||||
// return partialFriendship;
|
// return partialFriendship;
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
// return new SendableFriendship(friendship);
|
|
||||||
return sendFrienships;
|
return sendFrienships;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,8 +172,8 @@ export class FriendshipService {
|
|||||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
console.log('friendships services pendant friendships:')
|
// console.log('friendships services pendant friendships:')
|
||||||
console.log({...friendships})
|
// console.log({...friendships})
|
||||||
|
|
||||||
let sendFrienships: SendableFriendship[] = []
|
let sendFrienships: SendableFriendship[] = []
|
||||||
for (const friendship of friendships) {
|
for (const friendship of friendships) {
|
||||||
@@ -227,8 +191,8 @@ export class FriendshipService {
|
|||||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
console.log('friendship service received requests')
|
// console.log('friendship service received requests')
|
||||||
console.log({...friendships})
|
// console.log({...friendships})
|
||||||
|
|
||||||
let sendFrienships: SendableFriendship[] = []
|
let sendFrienships: SendableFriendship[] = []
|
||||||
for (const friendship of friendships) {
|
for (const friendship of friendships) {
|
||||||
@@ -237,22 +201,16 @@ export class FriendshipService {
|
|||||||
return sendFrienships;
|
return sendFrienships;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is no longer the right return
|
|
||||||
// async create(createFriendshipDto: CreateFriendshipDto, creator : User) : Promise <Partial<Friendship>> {
|
|
||||||
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
|
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
|
||||||
console.log("DTO : \n")
|
// console.log("DTO : \n")
|
||||||
console.log({...createFriendshipDto})
|
// console.log({...createFriendshipDto})
|
||||||
|
|
||||||
// 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})
|
|
||||||
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)
|
||||||
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
||||||
|
|
||||||
// const friendship = await this.friendshipRepository.findOneBy({ sender: creator, receiver: receiver });
|
|
||||||
|
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
@@ -260,54 +218,45 @@ export class FriendshipService {
|
|||||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
.where('sender.id = :senderId', {senderId: creator.id})
|
.where('sender.id = :senderId', {senderId: creator.id})
|
||||||
.andWhere('receiver.id = :receiverId', {receiverId: receiver.id})
|
.andWhere('receiver.id = :receiverId', {receiverId: receiver.id})
|
||||||
|
.orWhere('sender.id = :senderId2', {senderId2: receiver.id})
|
||||||
|
.andWhere('receiver.id = :receiverId2', {receiverId2: creator.id})
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
console.log('friendship.service create, friendship: \n\n\n')
|
// console.log('friendship.service create, friendship: \n\n\n')
|
||||||
// console.log({...friendship})
|
// console.log({...friendship})
|
||||||
|
|
||||||
if (friendship) {
|
if (friendship) {
|
||||||
console.log('there is already a friend request')
|
// console.log('there is already a friend request')
|
||||||
|
|
||||||
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);
|
||||||
else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED)
|
else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED) {
|
||||||
throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`, HttpStatus.OK);
|
if (friendship && friendship.sender && friendship.sender.id === creator.id) {
|
||||||
else if (friendship.status && friendship.status === FriendshipStatus.BLOCKED)
|
throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`, HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// console.log('the friend request is being updated to Accepted')
|
||||||
|
|
||||||
|
friendship.status = FriendshipStatus.ACCEPTED;
|
||||||
|
const saveAFriendship = await this.friendshipRepository.save(friendship);
|
||||||
|
return new SendableFriendship(saveAFriendship);
|
||||||
|
}
|
||||||
|
} else if (friendship.status && friendship.status === FriendshipStatus.BLOCKED)
|
||||||
throw new HttpException(`We can't do that`, HttpStatus.OK);
|
throw new HttpException(`We can't do that`, HttpStatus.OK);
|
||||||
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('friendship.service create, we are still saving a new friendship')
|
// console.log('friendship.service create, we are still saving a new friendship')
|
||||||
|
|
||||||
const newFriendship = new Friendship();
|
const newFriendship = new Friendship();
|
||||||
newFriendship.sender = creator;
|
newFriendship.sender = creator;
|
||||||
// newFriendship.senderUsername = creator.username;
|
|
||||||
// newFriendship.senderId = creator.id;
|
|
||||||
newFriendship.receiver = receiver;
|
newFriendship.receiver = receiver;
|
||||||
// newFriendship.receiverUsername = receiver.username;
|
|
||||||
// newFriendship.receiverId = receiver.id;
|
|
||||||
newFriendship.status = createFriendshipDto.status;
|
newFriendship.status = createFriendshipDto.status;
|
||||||
const savedFriendship = await this.friendshipRepository.save(newFriendship);
|
const savedFriendship = await this.friendshipRepository.save(newFriendship);
|
||||||
// const partialFriendship : Partial<Friendship> = {
|
|
||||||
// id : (await savedFriendship).id,
|
|
||||||
// date : (await savedFriendship).date,
|
|
||||||
// receiverUsername: (await savedFriendship).receiverUsername,
|
|
||||||
// receiverId: (await savedFriendship).receiverId,
|
|
||||||
// status : (await savedFriendship).status
|
|
||||||
// }
|
|
||||||
// console.log('friendship.service create friendship, partial friendship')
|
|
||||||
// console.log({...partialFriendship})
|
|
||||||
// console.log('friendship.service create friendship, NEW friendship')
|
|
||||||
// console.log({...newFriendship})
|
|
||||||
// console.log('friendship.service create friendship, SAVED friendship')
|
|
||||||
// console.log({...savedFriendship})
|
|
||||||
// return partialFriendship;
|
|
||||||
return new SendableFriendship(savedFriendship);
|
return new SendableFriendship(savedFriendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
async acceptFriendship(relationshipId: number, user: User) {
|
async acceptFriendship(relationshipId: number, user: User) {
|
||||||
// const relation = await this.friendshipRepository.findOneBy({id: relationshipId });
|
|
||||||
|
|
||||||
|
|
||||||
const relation = await this.friendshipRepository
|
const relation = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
@@ -315,8 +264,9 @@ export class FriendshipService {
|
|||||||
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
console.log('.service accept friendship')
|
// console.log('.service accept friendship')
|
||||||
console.log({...relation})
|
// 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);
|
||||||
if (relation.sender.id === user.id) {
|
if (relation.sender.id === user.id) {
|
||||||
@@ -324,17 +274,6 @@ export class FriendshipService {
|
|||||||
}
|
}
|
||||||
relation.status = FriendshipStatus.ACCEPTED;
|
relation.status = FriendshipStatus.ACCEPTED;
|
||||||
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,
|
|
||||||
// receiverId: (await savedFriendship).receiverId,
|
|
||||||
// status : (await savedFriendship).status
|
|
||||||
// }
|
|
||||||
// console.log('.service accept friendship END')
|
|
||||||
// console.log({...partialFriendship})
|
|
||||||
|
|
||||||
// return partialFriendship;
|
|
||||||
return new SendableFriendship(savedFriendship);
|
return new SendableFriendship(savedFriendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,45 +294,28 @@ export class FriendshipService {
|
|||||||
return new SendableFriendship(savedFriendship);
|
return new SendableFriendship(savedFriendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ok i decided you can't block someone who has already blocked you (cuz then you could unblock them and then they're blocking you would no longer apply, in a way negating their blocking of you.
|
||||||
async blockFriendship(relationshipId: number, user: User) {
|
async blockFriendship(relationshipId: number, user: User) {
|
||||||
const relation = await this.friendshipRepository
|
const relation = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
||||||
|
.andWhere('friendship.status != :friendshipStatus', { friendshipStatus: FriendshipStatus.BLOCKED })
|
||||||
.getOne();
|
.getOne();
|
||||||
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);
|
||||||
|
|
||||||
// do i need to check if they've already been blocked?
|
// in the case where you RECEIVED the friendship but now want to block that person
|
||||||
|
if (relation.receiver && relation.receiver.id === user.id) {
|
||||||
if (relation.receiver.id === user.id) {
|
// console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
||||||
// throw new HttpException(`You can't block yourself.`, HttpStatus.NOT_FOUND);
|
// console.log({...relation})
|
||||||
console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
|
||||||
console.log({...relation})
|
|
||||||
// const newFriendshipDto = new CreateFriendshipDto(relation[0].receiver, FriendshipStatus.BLOCKED)
|
|
||||||
// const newFriendshipDto = new CreateFriendshipDto({"receiverUsername": relation[0].receiver, "status": "R"})
|
|
||||||
// we create a new one where you are the sender
|
|
||||||
const newFriendshipDto = {"receiverUsername": relation.sender.username, "receiverId": relation.sender.id, "status": FriendshipStatus.BLOCKED};
|
const newFriendshipDto = {"receiverUsername": relation.sender.username, "receiverId": relation.sender.id, "status": FriendshipStatus.BLOCKED};
|
||||||
// can't do it this way cuz READONLY
|
|
||||||
// const newFriendshipDto = new CreateFriendshipDto();
|
|
||||||
// newFriendshipDto.receiverUsername = relation[0].sender.username;
|
|
||||||
// newFriendshipDto.status = FriendshipStatus.BLOCKED;
|
|
||||||
// we delete that relation
|
|
||||||
await this.removeFriendship(relationshipId, user);
|
await this.removeFriendship(relationshipId, user);
|
||||||
// we set it to blocked like we do below...
|
|
||||||
return await this.create(newFriendshipDto, user);
|
return await this.create(newFriendshipDto, user);
|
||||||
} else {
|
} else {
|
||||||
relation.status = FriendshipStatus.BLOCKED;
|
relation.status = FriendshipStatus.BLOCKED;
|
||||||
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,
|
|
||||||
// receiverId: (await savedFriendship).receiverId,
|
|
||||||
// status : (await savedFriendship).status
|
|
||||||
// }
|
|
||||||
// return partialFriendship
|
|
||||||
return new SendableFriendship(savedFriendship);
|
return new SendableFriendship(savedFriendship);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,25 +327,21 @@ export class FriendshipService {
|
|||||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
.where('friendship.id = :friendshipId', { friendshipId: relationshipId })
|
||||||
.getOne();
|
.getOne();
|
||||||
console.log('deleting a friendship .service')
|
|
||||||
console.log({...friendship})
|
|
||||||
console.log('who is the user')
|
|
||||||
console.log({...user})
|
|
||||||
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) {
|
if (friendship.sender.id !== user.id && friendship.receiver.id !== user.id) {
|
||||||
throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN);
|
throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN);
|
||||||
}
|
}
|
||||||
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...
|
|
||||||
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)
|
||||||
console.log('user to find: ' + userToFindId)
|
// console.log('user to find: ' + userToFindId)
|
||||||
|
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
@@ -449,13 +367,16 @@ 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;
|
||||||
}
|
}
|
||||||
console.log('we are not blocked in friendship service')
|
|
||||||
|
// console.log('we are not blocked in friendship service')
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,24 +37,7 @@ export class UsersController {
|
|||||||
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// actually fucking useless now...
|
|
||||||
// similar to @Get('myfriends/:friendUsername') but doesn't return a friendship just returns the user profile
|
|
||||||
// GET http://transcendance:8080/user?username=NomDuUser
|
// GET http://transcendance:8080/user?username=NomDuUser
|
||||||
// @UseGuards(AuthenticateGuard)
|
|
||||||
// @UseGuards(TwoFactorGuard)
|
|
||||||
// @Get()
|
|
||||||
// findOne(@Query('id') toFindId: number, @Req() req) {
|
|
||||||
// if (toFindId === undefined) {
|
|
||||||
// console.log("Backend Getting current user");
|
|
||||||
// return this.usersService.findOne(req.user.id);
|
|
||||||
// } else {
|
|
||||||
// const user : User = req.user;
|
|
||||||
// console.log('we have a query: ' + toFindId)
|
|
||||||
// return this.usersService.findOneById(user.id, toFindId);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// GET http://transcendance:8080/user
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
@Get()
|
||||||
@@ -69,16 +52,6 @@ export class UsersController {
|
|||||||
return this.usersService.findOne(usernameToFind);
|
return this.usersService.findOne(usernameToFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// also seems useless...
|
|
||||||
// GET http://transcendance:8080/user/stats
|
|
||||||
// @UseGuards(AuthenticateGuard)
|
|
||||||
// @UseGuards(TwoFactorGuard)
|
|
||||||
// @Get('stats')
|
|
||||||
// getStats(@Req() request) {
|
|
||||||
// return this.usersService.getStats(request.user.id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// PATCH http://transcendance:8080/user
|
// PATCH http://transcendance:8080/user
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
|
|||||||
@@ -22,23 +22,25 @@ export class UsersService {
|
|||||||
const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id});
|
const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id});
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
console.log(`The requested user not found.`);
|
// console.log(`The requested user not found.`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log(`The requested user found.`);
|
// console.log(`The requested user found.`);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(username: string) {
|
async findOne(username: string) {
|
||||||
console.log(`FIND ONE USER SERVICE Find user ${username}`);
|
// console.log(`FIND ONE USER SERVICE Find user ${username}`);
|
||||||
|
|
||||||
const user = await this.userRepository.createQueryBuilder('user')
|
const 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: username })
|
||||||
.getOne();
|
.getOne();
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new NotFoundException(`The requested user not found.`);
|
throw new NotFoundException(`The requested user not found.`);
|
||||||
console.log(`FIND ONE USER SERVICE The requested user found. ` + user.username + " "
|
|
||||||
+ user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
// console.log(`FIND ONE USER SERVICE The requested user found. ` + user.username + " " + user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
|
||||||
|
|
||||||
const partialUser : Partial<User> = {
|
const partialUser : Partial<User> = {
|
||||||
username: user.username,
|
username: user.username,
|
||||||
image_url: user.image_url,
|
image_url: user.image_url,
|
||||||
@@ -46,21 +48,25 @@ export class UsersService {
|
|||||||
status: user.status,
|
status: user.status,
|
||||||
stats: user.stats,
|
stats: user.stats,
|
||||||
};
|
};
|
||||||
console.log(`Returned Partial User.` + partialUser.username + user.username);
|
|
||||||
|
// console.log(`Returned Partial User.` + partialUser.username + user.username);
|
||||||
|
|
||||||
return partialUser;
|
return partialUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
||||||
console.log('searching for username: ' + usernameToSearch)
|
// console.log('searching for username: ' + usernameToSearch)
|
||||||
|
|
||||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||||
console.log({...user})
|
|
||||||
|
// console.log({...user})
|
||||||
|
|
||||||
if (!user)
|
if (!user)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(currentUser: User) {
|
async findAll(currentUser: User) {
|
||||||
// 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>[] = [];
|
||||||
@@ -76,8 +82,10 @@ export class UsersService {
|
|||||||
partialUsers.push({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({...partialUsers})
|
// console.log('user.services findAll, partialUsers:')
|
||||||
|
// console.log({...partialUsers})
|
||||||
|
|
||||||
return partialUsers;
|
return partialUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +105,7 @@ export class UsersService {
|
|||||||
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
||||||
// console.log({...updateUserDto})
|
// console.log({...updateUserDto})
|
||||||
if (await this.isUsernameExists(updateUserDto.username) === true) {
|
if (await this.isUsernameExists(updateUserDto.username) === true) {
|
||||||
console.log('updating username ' + updateUserDto.username + ' but it already is in use')
|
// console.log('updating username ' + updateUserDto.username + ' but it already is in use')
|
||||||
throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT);
|
throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT);
|
||||||
}
|
}
|
||||||
const user = await this.userRepository.preload(
|
const user = await this.userRepository.preload(
|
||||||
@@ -140,7 +148,6 @@ export class UsersService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doing search with username not id because userService.findOne doesn't return an Id anymore, just username... fuck this architecture is big trash...
|
// doing search with username not id because userService.findOne doesn't return an Id anymore, just username... fuck this architecture is big trash...
|
||||||
// async getAvatarUrl(id: number) {
|
|
||||||
async getAvatarUrl(username: string) {
|
async getAvatarUrl(username: string) {
|
||||||
const user = await this.userRepository.findOneBy({username: username});
|
const user = await this.userRepository.findOneBy({username: username});
|
||||||
if (!user)
|
if (!user)
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
WEBSITE_HOST=localhost
|
WEBSITE_HOST=transcendance
|
||||||
WEBSITE_PORT=8080
|
WEBSITE_PORT=8080
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
|
||||||
|
/* ProfileDisplayOneUser is the same as DisplayAUser except sources the username from params from router rather than
|
||||||
|
from a regular var. But yea it's functionally identical, seemed easier to just have a duplicate rather than figuring
|
||||||
|
out how to get a more complicated things to do 2 jobs.*/
|
||||||
|
|
||||||
|
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import GenerateUserDisplay from '../../pieces/GenerateUserDisplay.svelte';
|
||||||
|
|
||||||
|
export let params;
|
||||||
|
let user;
|
||||||
|
|
||||||
|
onMount( async() => {
|
||||||
|
|
||||||
|
// console.log('Display One User username: '+ params.username)
|
||||||
|
|
||||||
|
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=${params.username}`)
|
||||||
|
.then( (x) => x.json() );
|
||||||
|
console.log('in display ONE user')
|
||||||
|
console.log({...user})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="background-pages">
|
||||||
|
{#if user !== undefined}
|
||||||
|
<GenerateUserDisplay user={user}/>
|
||||||
|
{:else}
|
||||||
|
<h2>Sorry</h2>
|
||||||
|
<div>Failed to load user {params.username}</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<!-- This is where i might toss in an Invite to Game button ? -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { binding_callbacks, empty } from "svelte/internal"; // WTF is this?
|
|
||||||
import Button from "../../pieces/Button.svelte";
|
import Button from "../../pieces/Button.svelte";
|
||||||
import DisplayAUser from "../../pieces/DisplayAUser.svelte";
|
import DisplayAUser from "../../pieces/DisplayAUser.svelte";
|
||||||
import Tabs from "../../pieces/Tabs.svelte";
|
import Tabs from "../../pieces/Tabs.svelte";
|
||||||
|
|
||||||
let errors = {friendRequest: '',};
|
|
||||||
let set = {friendUsername: ''}
|
|
||||||
|
|
||||||
let user;
|
let user;
|
||||||
let allUsers;
|
let allUsers;
|
||||||
let myFriendships;
|
let myFriendships;
|
||||||
let requestsMade, requestsRecieved;
|
let requestsMade, requestsRecieved;
|
||||||
let blockedUsers;
|
let blockedUsers;
|
||||||
let usernameBeingViewed;
|
let usernameBeingViewed;
|
||||||
let friendshipStatusFull; // id, date, senderUsername, reveiverUsername, status
|
let friendshipStatusFull; // date, reveiverUsername, status
|
||||||
|
|
||||||
/**** Layout variables ****/
|
/**** Layout variables ****/
|
||||||
let tabItems: string[] = ['All Users', 'My Friends', 'Friend Requests', 'Blocked Users']
|
let tabItems: string[] = ['All Users', 'My Friends', 'Friend Requests', 'Blocked Users']
|
||||||
@@ -23,7 +19,6 @@
|
|||||||
|
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
|
|
||||||
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
|
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
|
|
||||||
@@ -45,6 +40,16 @@
|
|||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got all users ')
|
console.log('got all users ')
|
||||||
console.log({...allUsers})
|
console.log({...allUsers})
|
||||||
|
if (usernameBeingViewed !== undefined) {
|
||||||
|
let found = allUsers.find(e => e.username === usernameBeingViewed);
|
||||||
|
// console.log("SEARCHING ALL USERS: ")
|
||||||
|
// console.log({...found})
|
||||||
|
if (found === undefined) {
|
||||||
|
// console.log('none found')
|
||||||
|
usernameBeingViewed = undefined;
|
||||||
|
friendshipStatusFull = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// it's more like fetch friendships
|
// it's more like fetch friendships
|
||||||
@@ -52,6 +57,7 @@
|
|||||||
const fetchMyFriendships = async() => {
|
const fetchMyFriendships = async() => {
|
||||||
myFriendships = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/myfriends`)
|
myFriendships = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/myfriends`)
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('got my friends ')
|
console.log('got my friends ')
|
||||||
console.log({...myFriendships})
|
console.log({...myFriendships})
|
||||||
};
|
};
|
||||||
@@ -59,6 +65,7 @@
|
|||||||
const fetchRequestsMade = async() => {
|
const fetchRequestsMade = async() => {
|
||||||
requestsMade = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/pending`)
|
requestsMade = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/pending`)
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('got requests made ')
|
console.log('got requests made ')
|
||||||
console.log({...requestsMade})
|
console.log({...requestsMade})
|
||||||
};
|
};
|
||||||
@@ -66,6 +73,7 @@
|
|||||||
const fetchRequestsReceived = async() => {
|
const fetchRequestsReceived = async() => {
|
||||||
requestsRecieved = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/received`)
|
requestsRecieved = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/received`)
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('got requests received ')
|
console.log('got requests received ')
|
||||||
console.log({...requestsRecieved})
|
console.log({...requestsRecieved})
|
||||||
};
|
};
|
||||||
@@ -73,6 +81,7 @@
|
|||||||
const fetchBlockedUsers = async() => {
|
const fetchBlockedUsers = async() => {
|
||||||
blockedUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/blocked`)
|
blockedUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/blocked`)
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('got blocked users, is it empty?')
|
console.log('got blocked users, is it empty?')
|
||||||
console.log({...blockedUsers})
|
console.log({...blockedUsers})
|
||||||
console.log(Object.keys(blockedUsers))
|
console.log(Object.keys(blockedUsers))
|
||||||
@@ -83,8 +92,10 @@
|
|||||||
const fetchFriendshipFull = async(aUsername) => {
|
const fetchFriendshipFull = async(aUsername) => {
|
||||||
console.log('fetch friendship from a username')
|
console.log('fetch friendship from a username')
|
||||||
console.log(aUsername)
|
console.log(aUsername)
|
||||||
|
|
||||||
friendshipStatusFull = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/myfriends?username=${aUsername}`)
|
friendshipStatusFull = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/myfriends?username=${aUsername}`)
|
||||||
.then( x => x.json());
|
.then( x => x.json());
|
||||||
|
|
||||||
console.log({...friendshipStatusFull})
|
console.log({...friendshipStatusFull})
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,6 +103,7 @@
|
|||||||
const sendFriendRequest = async(aUsername) => {
|
const sendFriendRequest = async(aUsername) => {
|
||||||
console.log('sending a friend request')
|
console.log('sending a friend request')
|
||||||
console.log(aUsername)
|
console.log(aUsername)
|
||||||
|
|
||||||
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations`, {
|
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations`, {
|
||||||
method : "POST",
|
method : "POST",
|
||||||
headers: { 'Content-Type': 'application/json'},
|
headers: { 'Content-Type': 'application/json'},
|
||||||
@@ -102,17 +114,14 @@
|
|||||||
})
|
})
|
||||||
.then( x => x.json())
|
.then( x => x.json())
|
||||||
// .catch( x => console.log({...x}))
|
// .catch( x => console.log({...x}))
|
||||||
// "status": "A"
|
await fetchFriendshipFull(aUsername);
|
||||||
console.log({...resp})
|
await fetchAll();
|
||||||
fetchFriendshipFull(aUsername);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewAUser = async(aUsername) => {
|
const viewAUser = async(aUsername) => {
|
||||||
console.log('Profile Friend updating userBeingViewed')
|
console.log('Profile Friend updating userBeingViewed')
|
||||||
usernameBeingViewed = aUsername;
|
|
||||||
|
|
||||||
// friendshipStatusFull = undefined;
|
usernameBeingViewed = aUsername;
|
||||||
// id, date, senderUsername, reveiverUsername, status
|
|
||||||
await fetchFriendshipFull(aUsername);
|
await fetchFriendshipFull(aUsername);
|
||||||
|
|
||||||
console.log('Friendship Status Full')
|
console.log('Friendship Status Full')
|
||||||
@@ -125,39 +134,34 @@
|
|||||||
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}/accept`, {
|
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${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...
|
|
||||||
console.log('accepted friend request, now response')
|
|
||||||
console.log({...resp})
|
|
||||||
await fetchFriendshipFull(usernameBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
|
await fetchAll();
|
||||||
// will this make it reload? C'est un peu bourain... do i even need it?
|
|
||||||
activeTabItem = activeTabItem;
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const declineFriendRequest = async(relationshipId) => {
|
const declineFriendRequest = async(relationshipId) => {
|
||||||
console.log('decline friend request')
|
console.log('decline friend request')
|
||||||
|
|
||||||
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}/decline`, {
|
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}/decline`, {
|
||||||
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...
|
|
||||||
console.log('declined friend request, now response')
|
|
||||||
console.log({...resp})
|
|
||||||
await fetchFriendshipFull(usernameBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
|
await fetchAll();
|
||||||
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const unfriend = async(relationshipId) => {
|
const unfriend = async(relationshipId) => {
|
||||||
console.log('Unfriend')
|
console.log('Unfriend')
|
||||||
|
|
||||||
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}`, {
|
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}`, {
|
||||||
method: "DELETE"})
|
method: "DELETE"})
|
||||||
.then( x => x.json());
|
.then( x => x.json());
|
||||||
|
|
||||||
// friendshipStatusFull = undefined;
|
|
||||||
// OR
|
|
||||||
await fetchFriendshipFull(usernameBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
if (Object.keys(friendshipStatusFull).length === 0)
|
if (Object.keys(friendshipStatusFull).length === 0)
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
// will this make it reload? C'est un peu bourain... do i even need it?
|
await fetchAll();
|
||||||
activeTabItem = activeTabItem;
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -174,34 +178,37 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then( x => x.json())
|
.then( x => x.json())
|
||||||
await fetchBlockedUsers();
|
// await fetchBlockedUsers();
|
||||||
await fetchAllUsers();
|
// await fetchAllUsers();
|
||||||
|
await fetchAll();
|
||||||
usernameBeingViewed = undefined;
|
usernameBeingViewed = undefined;
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
// will this make it reload?
|
|
||||||
activeTabItem = activeTabItem;
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const blockAFriend = async(relationshipId) => {
|
const blockAFriend = async(relationshipId) => {
|
||||||
console.log('blocking a friend, the relationshipID')
|
console.log('blocking a friend, the relationshipID')
|
||||||
console.log(relationshipId)
|
console.log(relationshipId)
|
||||||
|
|
||||||
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}/block`, {method: "PATCH"})
|
const resp = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/network/relations/${relationshipId}/block`, {method: "PATCH"})
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('blocked a user response')
|
console.log('blocked a user response')
|
||||||
console.log({...resp})
|
console.log({...resp})
|
||||||
await fetchBlockedUsers();
|
// await fetchBlockedUsers();
|
||||||
await fetchAllUsers();
|
// await fetchAllUsers();
|
||||||
|
await fetchAll();
|
||||||
usernameBeingViewed = undefined;
|
usernameBeingViewed = undefined;
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
// will this make it reload?
|
// reloads active tab so you get blocked users for example
|
||||||
activeTabItem = activeTabItem;
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const unblockAUser = async(relationshipId) => {
|
const unblockAUser = async(relationshipId) => {
|
||||||
// it's basically the same as unfriending someone cuz unfriending them means the relationship is deleted
|
// it's basically the same as unfriending someone cuz unfriending them means the relationship is deleted
|
||||||
await unfriend(relationshipId);
|
await unfriend(relationshipId);
|
||||||
|
activeTabItem = activeTabItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
const switchTab = async(e) => {
|
const switchTab = async(e) => {
|
||||||
@@ -214,31 +221,26 @@
|
|||||||
await fetchRequestsReceived();
|
await fetchRequestsReceived();
|
||||||
} else if (activeTabItem === 'Blocked Users') {
|
} else if (activeTabItem === 'Blocked Users') {
|
||||||
await fetchBlockedUsers();
|
await fetchBlockedUsers();
|
||||||
console.log('blocked users: ')
|
console.log('fetching blocked users')
|
||||||
console.log({...blockedUsers})
|
|
||||||
}
|
}
|
||||||
|
if (usernameBeingViewed !== undefined)
|
||||||
|
fetchFriendshipFull(usernameBeingViewed);
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<div class="background-pages">
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
|
<div class="background-pages">
|
||||||
<div class="top-grid">
|
<div class="top-grid">
|
||||||
|
|
||||||
<!-- let tabItems: string[] = ['All Users', 'My Friends', 'Friend Requests']
|
<!-- let tabItems: string[] = ['All Users', 'My Friends', 'Friend Requests']
|
||||||
let activeTabItem: string = 'All Users'; -->
|
let activeTabItem: string = 'All Users'; -->
|
||||||
|
|
||||||
<!-- maybe add numbers at the botton? like for how many of each there are? -->
|
|
||||||
|
|
||||||
<div class="sidebar-list">
|
<div class="sidebar-list">
|
||||||
<Tabs items={tabItems} activeItem={activeTabItem} size="small" on:tabChange={switchTab}/>
|
<Tabs items={tabItems} activeItem={activeTabItem} size="small" on:tabChange={switchTab}/>
|
||||||
{#if activeTabItem === 'All Users' && allUsers !== undefined}
|
{#if activeTabItem === 'All Users' && allUsers !== undefined}
|
||||||
<h3>{activeTabItem}</h3>
|
<h3>{activeTabItem}</h3>
|
||||||
<!-- 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? -->
|
|
||||||
<!-- add a thing so it doesn't display the current user just all the other users -->
|
|
||||||
|
|
||||||
{#if Object.keys(allUsers).length === 0}
|
{#if Object.keys(allUsers).length === 0}
|
||||||
<div class="tip">You are alone on this platform...</div>
|
<div class="tip">You are alone on this platform...</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -258,7 +260,6 @@
|
|||||||
{#if Object.keys(myFriendships).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 myFriendships as aFriendship}
|
{#each myFriendships as aFriendship}
|
||||||
{#if aFriendship.senderUsername !== user.username}
|
{#if aFriendship.senderUsername !== user.username}
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aFriendship.senderUsername)}>{aFriendship.senderUsername}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aFriendship.senderUsername)}>{aFriendship.senderUsername}</div>
|
||||||
@@ -272,7 +273,6 @@
|
|||||||
{#if Object.keys(requestsRecieved).length === 0}
|
{#if Object.keys(requestsRecieved).length === 0}
|
||||||
<div class="tip">You don't have any Friend Requests</div>
|
<div class="tip">You don't have any Friend Requests</div>
|
||||||
{/if}
|
{/if}
|
||||||
<!-- {#each requestsRecieved as aUser (aUser.id)} -->
|
|
||||||
{#each requestsRecieved as aUser}
|
{#each requestsRecieved as aUser}
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aUser.senderUsername)}>{aUser.senderUsername}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aUser.senderUsername)}>{aUser.senderUsername}</div>
|
||||||
<div class="status sidebar-item">{aUser.status}</div>
|
<div class="status sidebar-item">{aUser.status}</div>
|
||||||
@@ -284,7 +284,6 @@
|
|||||||
{#if Object.keys(blockedUsers).length === 0}
|
{#if Object.keys(blockedUsers).length === 0}
|
||||||
<div class="tip">You have not Blocked any Users</div>
|
<div class="tip">You have not Blocked any Users</div>
|
||||||
{/if}
|
{/if}
|
||||||
<!-- {#each blockedUsers as aUser (aUser.id)} -->
|
|
||||||
{#each blockedUsers as aUser}
|
{#each blockedUsers as aUser}
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aUser.receiverUsername)}>{aUser.receiverUsername}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aUser.receiverUsername)}>{aUser.receiverUsername}</div>
|
||||||
<div class="status sidebar-item">{aUser.status}</div>
|
<div class="status sidebar-item">{aUser.status}</div>
|
||||||
@@ -296,7 +295,6 @@
|
|||||||
|
|
||||||
<div class="main-display">
|
<div class="main-display">
|
||||||
{#if usernameBeingViewed !== undefined}
|
{#if usernameBeingViewed !== undefined}
|
||||||
<!-- <DisplayAUser aUsername={usernameBeingViewed}/> -->
|
|
||||||
<DisplayAUser aUsername={usernameBeingViewed}/>
|
<DisplayAUser aUsername={usernameBeingViewed}/>
|
||||||
|
|
||||||
<div class="buttons-area">
|
<div class="buttons-area">
|
||||||
@@ -305,7 +303,6 @@
|
|||||||
{#if friendshipStatusFull.senderUsername === user.username}
|
{#if friendshipStatusFull.senderUsername === user.username}
|
||||||
<div class="tile">Friend Request Sent</div>
|
<div class="tile">Friend Request Sent</div>
|
||||||
{:else}
|
{:else}
|
||||||
<!-- <Button type="secondary" on:click={() => acceptFriendRequest(usernameBeingViewed)}>Unfriend</Button> -->
|
|
||||||
<Button type="secondary" on:click={() => acceptFriendRequest(friendshipStatusFull.id)}>Accept Friend Request</Button>
|
<Button type="secondary" on:click={() => acceptFriendRequest(friendshipStatusFull.id)}>Accept Friend Request</Button>
|
||||||
<Button on:click={() => declineFriendRequest(friendshipStatusFull.id)}>Decline Friend Request</Button>
|
<Button on:click={() => declineFriendRequest(friendshipStatusFull.id)}>Decline Friend Request</Button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -331,7 +328,6 @@
|
|||||||
<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> -->
|
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div class="placeholder">
|
<div class="placeholder">
|
||||||
@@ -343,6 +339,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
/* ok so i want a 12 column grid with a sidebar */
|
/* ok so i want a 12 column grid with a sidebar */
|
||||||
@@ -1,51 +1,32 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|
||||||
import { onMount, afterUpdate } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import GenerateUserDisplay from './GenerateUserDisplay.svelte';
|
import GenerateUserDisplay from './GenerateUserDisplay.svelte';
|
||||||
|
|
||||||
// export let aUsername;
|
|
||||||
export let aUsername;
|
export let aUsername;
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
console.log('Display aUser username: '+ aUsername)
|
// console.log('Display aUser username: '+ aUsername)
|
||||||
//`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=NomDuUserATrouve`
|
|
||||||
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=${aUsername}`)
|
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=${aUsername}`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
})
|
})
|
||||||
|
|
||||||
// sadly created an infinite loop
|
|
||||||
// afterUpdate( async() => {
|
|
||||||
// console.log('Display Update aUser username: '+ aUsername)
|
|
||||||
// // http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
|
||||||
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
|
||||||
// .then( (x) => x.json() );
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
export const updateUser = async() => {
|
export const updateUser = async() => {
|
||||||
// console.log('Display Update aUser username: '+ aUsername)
|
|
||||||
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
|
||||||
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
|
||||||
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=${aUsername}`)
|
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user?username=${aUsername}`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
};
|
};
|
||||||
|
|
||||||
// $: aUsername, updateUser();
|
|
||||||
$: aUsername, updateUser();
|
$: aUsername, updateUser();
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class="background-pages">
|
||||||
{#if user !== undefined}
|
{#if user !== undefined}
|
||||||
<GenerateUserDisplay user={user}/>
|
<GenerateUserDisplay user={user}/>
|
||||||
{:else}
|
{:else}
|
||||||
<h2>Sorry</h2>
|
<h2>Sorry</h2>
|
||||||
<div>Failed to load user {aUsername}</div>
|
<div>Failed to load user {aUsername}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -9,11 +9,12 @@
|
|||||||
let avatar;
|
let avatar;
|
||||||
// avatar needs to be updated!!!
|
// avatar needs to be updated!!!
|
||||||
console.log('Generate User Display, BEFORE on mount ' + avatar)
|
console.log('Generate User Display, BEFORE on mount ' + avatar)
|
||||||
// add errors
|
console.log('user:')
|
||||||
|
console.log({...user})
|
||||||
|
// console.log(user)
|
||||||
let errors = {avatar: ''};
|
let errors = {avatar: ''};
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
// console.log('Generate User Display, on mount ' + user.username)
|
|
||||||
avatar = await fetchAvatar(user.username);
|
avatar = await fetchAvatar(user.username);
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -90,10 +91,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<section class="main-stats">
|
<section class="main-stats">
|
||||||
<h4>Match Statistics</h4>
|
<h4>Match Statistics</h4>
|
||||||
<p>Total: {user.stats.totalGame}</p>
|
|
||||||
<p>Victories: {user.stats.winGame}</p>
|
<p>Victories: {user.stats.winGame}</p>
|
||||||
<p>Losses: {user.stats.loseGame}</p>
|
<p>Losses: {user.stats.loseGame}</p>
|
||||||
<p>Draws: {user.stats.drawGame}</p>
|
<p>Draws: {user.stats.drawGame}</p>
|
||||||
|
<p class="highlight">Total: {user.stats.totalGame}</p>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -142,6 +143,7 @@
|
|||||||
font-size: 1.5em;
|
font-size: 1.5em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding-bottom: 5px;
|
padding-bottom: 5px;
|
||||||
|
/* color: white; */
|
||||||
}
|
}
|
||||||
|
|
||||||
div.rank {
|
div.rank {
|
||||||
@@ -156,6 +158,30 @@
|
|||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.highlight {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.highlight{
|
||||||
|
grid-column: 1 / span 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 500px) {
|
||||||
|
section.main-stats{
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
section.main-stats h4{
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
section.main-stats p{
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Glittery Star Stuff */
|
/* Glittery Star Stuff */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<button class:selected="{current === '/spectator'}" on:click={() => (push('/spectator'))}>Spectate</button>
|
<button class:selected="{current === '/spectator'}" on:click={() => (push('/spectator'))}>Spectate</button>
|
||||||
<button class:selected="{current === '/ranking'}" on:click={() => (push('/ranking'))}>Ranking</button>
|
<button class:selected="{current === '/ranking'}" on:click={() => (push('/ranking'))}>Ranking</button>
|
||||||
<button class:selected="{current === '/profile'}" on:click={() => (push('/profile'))}>My Profile</button>
|
<button class:selected="{current === '/profile'}" on:click={() => (push('/profile'))}>My Profile</button>
|
||||||
<button class:selected="{current === '/profile/friends'}" on:click={() => (push('/profile/friends'))}>Friends</button>
|
<button class:selected="{current === '/profile/users'}" on:click={() => (push('/profile/users'))}>Users</button>
|
||||||
</div>
|
</div>
|
||||||
<button class="logout" on:click={handleClickLogout}>Log Out</button>
|
<button class="logout" on:click={handleClickLogout}>Log Out</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
import NotFound from "../pages/NotFound.svelte";
|
import NotFound from "../pages/NotFound.svelte";
|
||||||
import ProfileDisplay from '../pages/profile/ProfileDisplay.svelte';
|
import ProfileDisplay from '../pages/profile/ProfileDisplay.svelte';
|
||||||
import ProfileSettings from '../pages/profile/ProfileSettings.svelte';
|
import ProfileSettings from '../pages/profile/ProfileSettings.svelte';
|
||||||
import ProfileFriends from '../pages/profile/ProfileFriends.svelte';
|
import ProfileUsers from '../pages/profile/ProfileUsers.svelte';
|
||||||
import { wrap } from 'svelte-spa-router/wrap'
|
import ProfileDisplayOneUser from "../pages/profile/ProfileDisplayOneUser.svelte";
|
||||||
|
|
||||||
|
import DisplayAUser from '../pieces/DisplayAUser.svelte';
|
||||||
|
|
||||||
// establishing the prefix here very clearly so we can have a coherent repeatable structure
|
// establishing the prefix here very clearly so we can have a coherent repeatable structure
|
||||||
export const prefix = '/profile';
|
export const prefix = '/profile';
|
||||||
@@ -11,39 +13,8 @@ export const prefix = '/profile';
|
|||||||
export const profileRoutes = {
|
export const profileRoutes = {
|
||||||
'/': ProfileDisplay,
|
'/': ProfileDisplay,
|
||||||
'/settings': ProfileSettings,
|
'/settings': ProfileSettings,
|
||||||
'/friends': ProfileFriends,
|
'/users': ProfileUsers,
|
||||||
|
'/users/:username': ProfileDisplayOneUser,
|
||||||
|
// '/users/:username': DisplayAUser,
|
||||||
'*': NotFound
|
'*': NotFound
|
||||||
};
|
};
|
||||||
|
|
||||||
// I think the conditions of access like are you authenticated work best when they are on the parent routes not the nested routes cuz i don't want my header showing up
|
|
||||||
|
|
||||||
// export const profileRoutes = {
|
|
||||||
// '/': wrap({
|
|
||||||
// component: ProfileDisplay,
|
|
||||||
// conditions: [
|
|
||||||
// (detail) => {
|
|
||||||
// const { fortyTwo, tfa } = get(loginStatus);
|
|
||||||
// console.log(fortyTwo);
|
|
||||||
// console.log(tfa);
|
|
||||||
// console.log('in Profile Display');
|
|
||||||
// // return true;
|
|
||||||
// return (fortyTwo && tfa);
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }),
|
|
||||||
// '/settings': wrap({
|
|
||||||
// component: ProfileSettings,
|
|
||||||
// conditions: [
|
|
||||||
// (detail) => {
|
|
||||||
// const { fortyTwo, tfa } = get(loginStatus);
|
|
||||||
// // console.log(fortyTwo);
|
|
||||||
// // console.log(tfa);
|
|
||||||
// // return true;
|
|
||||||
// return (fortyTwo && tfa);
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// }),
|
|
||||||
// '*': NotFound
|
|
||||||
// };
|
|
||||||
|
|
||||||
// what if i did /#/profile/:id for like not the user? and then based on that did a fetch?
|
|
||||||
Reference in New Issue
Block a user