ok after talking with cherif we decided not to send things like the user.id so i need to recreate more or less what i had before, but i'm gonna keep using the user.id everywhere in the back and keep my better simpler friendship.entity, working on all that now, got a thing that compiles in the front and back, a few more things to fix and then test everything
This commit is contained in:
@@ -2,12 +2,12 @@ import { IsEnum, IsNotEmpty, IsString, IsPositive } from 'class-validator';
|
|||||||
import { FriendshipStatus } from '../entities/friendship.entity';
|
import { FriendshipStatus } from '../entities/friendship.entity';
|
||||||
|
|
||||||
export class CreateFriendshipDto {
|
export class CreateFriendshipDto {
|
||||||
@IsPositive()
|
// @IsPositive()
|
||||||
// @Max(1000) ?
|
// @Max(1000) ?
|
||||||
readonly receiverId: number;
|
// readonly receiverId: number;
|
||||||
// @IsNotEmpty()
|
@IsNotEmpty()
|
||||||
// @IsString()
|
@IsString()
|
||||||
// readonly receiverUsername: string;
|
readonly receiverUsername: string;
|
||||||
@IsEnum(FriendshipStatus)
|
@IsEnum(FriendshipStatus)
|
||||||
readonly status: FriendshipStatus;
|
readonly status: FriendshipStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,10 @@ export class FriendshipController {
|
|||||||
@Get('myfriends')
|
@Get('myfriends')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
findOne(@Query('username') otherUsername: string, @Query('id') id: number, @Req() req) {
|
findOne(@Query('username') otherUsername: string, @Req() req) {
|
||||||
console.log('GET myfriend')
|
console.log('GET myfriend')
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
if (id !== undefined) {
|
if (otherUsername !== undefined) {
|
||||||
return this.friendshipService.findOneRelationshipById(id, user.id)
|
|
||||||
} else if (otherUsername !== undefined) {
|
|
||||||
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
|
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
|
||||||
}
|
}
|
||||||
// might change this
|
// might change this
|
||||||
@@ -59,7 +57,7 @@ export class FriendshipController {
|
|||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
if (user.id !== createFriendshipDto.receiverId)
|
if (user.username !== createFriendshipDto.receiverUsername)
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -124,8 +122,11 @@ 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(relationshipId)
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
if (relationshipId === undefined)
|
// if (relationshipId === undefined)
|
||||||
|
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);
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export class FriendshipService {
|
|||||||
|
|
||||||
// lets see what happens here, doing directly receiver.id not LeftJoinAndSelect ...
|
// lets see what happens here, doing directly receiver.id not LeftJoinAndSelect ...
|
||||||
async findAllFriends(userId: number) {
|
async findAllFriends(userId: number) {
|
||||||
const friendship = await this.friendshipRepository
|
const friendships = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.leftJoinAndSelect('friendship.sender', 'sender')
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
@@ -115,7 +115,13 @@ export class FriendshipService {
|
|||||||
// for (const friend of friendship)
|
// for (const friend of friendship)
|
||||||
// console.log("FRIENDSHIP : " + friend.status);
|
// console.log("FRIENDSHIP : " + friend.status);
|
||||||
// return friendship;
|
// return friendship;
|
||||||
return new SendableFriendship(friendship);
|
// return new SendableFriendship(friendship);
|
||||||
|
let sendFrienships: SendableFriendship[] = []
|
||||||
|
for (const friendship of friendships) {
|
||||||
|
sendFrienships.push(new SendableFriendship(friendship));
|
||||||
|
}
|
||||||
|
// return new SendableFriendship(friendship);
|
||||||
|
return sendFrienships;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneBlocked(friendshipId: number, userId: number) {
|
async findOneBlocked(friendshipId: number, userId: number) {
|
||||||
@@ -225,7 +231,7 @@ export class FriendshipService {
|
|||||||
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})
|
||||||
const receiver = await this.userRepository.findOneBy({id: createFriendshipDto.receiverId});
|
const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername});
|
||||||
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)
|
||||||
@@ -278,7 +284,7 @@ export class FriendshipService {
|
|||||||
// 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.senderId === 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);
|
||||||
}
|
}
|
||||||
relation.status = FriendshipStatus.ACCEPTED;
|
relation.status = FriendshipStatus.ACCEPTED;
|
||||||
@@ -301,7 +307,7 @@ export class FriendshipService {
|
|||||||
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.senderId === user.id) {
|
if (relation.sender.id === user.id) {
|
||||||
throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`You can't decline your own request.`, HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
relation.status = FriendshipStatus.DECLINED;
|
relation.status = FriendshipStatus.DECLINED;
|
||||||
@@ -325,14 +331,14 @@ export class FriendshipService {
|
|||||||
|
|
||||||
// do i need to check if they've already been blocked?
|
// do i need to check if they've already been blocked?
|
||||||
|
|
||||||
if (relation.receiverId === user.id) {
|
if (relation.receiver.id === user.id) {
|
||||||
// throw new HttpException(`You can't block yourself.`, HttpStatus.NOT_FOUND);
|
// throw new HttpException(`You can't block yourself.`, HttpStatus.NOT_FOUND);
|
||||||
console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
|
||||||
console.log({...relation})
|
console.log({...relation})
|
||||||
// const newFriendshipDto = new CreateFriendshipDto(relation[0].receiver, FriendshipStatus.BLOCKED)
|
// const newFriendshipDto = new CreateFriendshipDto(relation[0].receiver, FriendshipStatus.BLOCKED)
|
||||||
// const newFriendshipDto = new CreateFriendshipDto({"receiverUsername": relation[0].receiver, "status": "R"})
|
// const newFriendshipDto = new CreateFriendshipDto({"receiverUsername": relation[0].receiver, "status": "R"})
|
||||||
// we create a new one where you are the sender
|
// we create a new one where you are the sender
|
||||||
const newFriendshipDto = {"receiverUsername": relation.senderUsername, "receiverId": relation.senderId, "status": FriendshipStatus.BLOCKED};
|
const newFriendshipDto = {"receiverUsername": relation.sender.username, "receiverId": relation.sender.id, "status": FriendshipStatus.BLOCKED};
|
||||||
// can't do it this way cuz READONLY
|
// can't do it this way cuz READONLY
|
||||||
// const newFriendshipDto = new CreateFriendshipDto();
|
// const newFriendshipDto = new CreateFriendshipDto();
|
||||||
// newFriendshipDto.receiverUsername = relation[0].sender.username;
|
// newFriendshipDto.receiverUsername = relation[0].sender.username;
|
||||||
@@ -366,7 +372,7 @@ export class FriendshipService {
|
|||||||
console.log({...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.senderId !== user.id && friendship.receiverId !== 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')
|
||||||
|
|||||||
@@ -62,15 +62,15 @@ export class UsersController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
@Get()
|
||||||
findOne(@Query('id') toFindId: number, @Req() req) {
|
findOne(@Query('username') usernameToFind: string, @Req() req) {
|
||||||
console.log('users service findOne toFindId:')
|
console.log('users service findOne usernameToFind:')
|
||||||
console.log(toFindId)
|
console.log(usernameToFind)
|
||||||
console.log('users service findOne my Id:')
|
console.log('users service findOne my Username:')
|
||||||
console.log(req.user.id)
|
console.log(req.user.username)
|
||||||
if (toFindId === undefined)
|
if (usernameToFind === undefined)
|
||||||
return this.usersService.findOne(req.user.id);
|
return this.usersService.findOne(req.user.username);
|
||||||
else
|
else
|
||||||
return this.usersService.findOne(toFindId);
|
return this.usersService.findOne(usernameToFind);
|
||||||
// i would rather just use numbers but i'm guessing Cherif uses this all over
|
// i would rather just use numbers but i'm guessing Cherif uses this all over
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ export class UsersService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: number) {
|
async findOne(username: string) {
|
||||||
console.log(`FIND ONE USER SERVICE Find user ${id}`);
|
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.id = :id', { id: id })
|
.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.`);
|
||||||
@@ -53,6 +53,9 @@ export class UsersService {
|
|||||||
return partialUser;
|
return partialUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***** THIS IS THE THING I REALLY NEED TO FIX!!!!!!! *****/
|
||||||
|
|
||||||
// Ok this gets called in the Authenitcation Service, but like i was still able to make a username === someone else's
|
// Ok this gets called in the Authenitcation Service, but like i was still able to make a username === someone else's
|
||||||
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
||||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||||
@@ -123,28 +126,28 @@ export class UsersService {
|
|||||||
return this.userRepository.save(user);
|
return this.userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, updateUserDto: UpdateUsersDto) {
|
async update(id: number, updateUserDto: UpdateUsersDto) {
|
||||||
console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
||||||
const user = await this.userRepository.preload(
|
const user = await this.userRepository.preload(
|
||||||
{id: +id,
|
{id: id,
|
||||||
...updateUserDto});
|
...updateUserDto});
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException(`The user could not be updated.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user could not be updated.`,HttpStatus.NOT_FOUND);
|
||||||
return this.userRepository.save(user);
|
return this.userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string) {
|
async remove(id: number) {
|
||||||
const user = await this.userRepository.findOneBy({id: +id});
|
const user = await this.userRepository.findOneBy({id: id});
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException(`The user could not be deleted.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user could not be deleted.`,HttpStatus.NOT_FOUND);
|
||||||
return this.userRepository.remove(user);
|
return this.userRepository.remove(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
async enableTwoFactorAuth(id: string) {
|
async enableTwoFactorAuth(id: number) {
|
||||||
return this.userRepository.update(id, {isEnabledTwoFactorAuth: true});
|
return this.userRepository.update(id, {isEnabledTwoFactorAuth: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
async authenticateUserWith2FA(id: string) {
|
async authenticateUserWith2FA(id: number) {
|
||||||
return this.userRepository.update(id, { isTwoFactorAuthenticated: true})
|
return this.userRepository.update(id, { isTwoFactorAuthenticated: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
let myFriends;
|
let myFriends;
|
||||||
let requestsMade, requestsRecieved;
|
let requestsMade, requestsRecieved;
|
||||||
let blockedUsers;
|
let blockedUsers;
|
||||||
let userIdBeingViewed;
|
let usernameBeingViewed;
|
||||||
let friendshipStatusFull; // id, date, senderUsername, reveiverUsername, status
|
let friendshipStatusFull; // id, date, senderUsername, reveiverUsername, status
|
||||||
|
|
||||||
/**** Layout variables ****/
|
/**** Layout variables ****/
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchMyFriends = async() => {
|
const fetchMyFriends = async() => {
|
||||||
myFriends = await fetch('http://transcendance:8080/api/v2/network/relations')
|
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got my friends ')
|
console.log('got my friends ')
|
||||||
console.log({...myFriends})
|
console.log({...myFriends})
|
||||||
@@ -90,10 +90,10 @@
|
|||||||
/**** END OF MAIN FETCH ****/
|
/**** END OF MAIN FETCH ****/
|
||||||
|
|
||||||
// returns everything but BLOCKED
|
// returns everything but BLOCKED
|
||||||
const fetchFriendshipFull = async(aUserId) => {
|
const fetchFriendshipFull = async(aUsername) => {
|
||||||
console.log('fetch friendship from a username')
|
console.log('fetch friendship from a username')
|
||||||
console.log(aUserId)
|
console.log(aUsername)
|
||||||
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/relations/${aUserId}`)
|
friendshipStatusFull = await fetch(`http://transcendance:8080/api/v2/network/myfriends/${aUsername}`)
|
||||||
.then( x => x.json());
|
.then( x => x.json());
|
||||||
console.log({...friendshipStatusFull})
|
console.log({...friendshipStatusFull})
|
||||||
};
|
};
|
||||||
@@ -105,21 +105,20 @@
|
|||||||
headers: { 'Content-Type': 'application/json'},
|
headers: { 'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"receiverUsername": aUser.username,
|
"receiverUsername": aUser.username,
|
||||||
"receiverId": aUser.id,
|
|
||||||
"status": "R"
|
"status": "R"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then( x => x.json())
|
.then( x => x.json())
|
||||||
fetchFriendshipFull(aUser.id);
|
fetchFriendshipFull(aUser.username);
|
||||||
};
|
};
|
||||||
|
|
||||||
const viewAUser = async(aUserId) => {
|
const viewAUser = async(aUsername) => {
|
||||||
console.log('Profile Friend updating userBeingViewed')
|
console.log('Profile Friend updating userBeingViewed')
|
||||||
userIdBeingViewed = aUserId;
|
usernameBeingViewed = aUsername;
|
||||||
|
|
||||||
// friendshipStatusFull = undefined;
|
// friendshipStatusFull = undefined;
|
||||||
// id, date, senderUsername, reveiverUsername, status
|
// id, date, senderUsername, reveiverUsername, status
|
||||||
await fetchFriendshipFull(aUserId);
|
await fetchFriendshipFull(aUsername);
|
||||||
|
|
||||||
console.log('Friendship Status Full')
|
console.log('Friendship Status Full')
|
||||||
console.log({...friendshipStatusFull})
|
console.log({...friendshipStatusFull})
|
||||||
@@ -135,7 +134,7 @@
|
|||||||
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
|
// 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('accepted friend request, now response')
|
||||||
console.log({...resp})
|
console.log({...resp})
|
||||||
await fetchFriendshipFull(userIdBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
|
|
||||||
// will this make it reload? C'est un peu bourain... do i even need it?
|
// will this make it reload? C'est un peu bourain... do i even need it?
|
||||||
activeTabItem = activeTabItem;
|
activeTabItem = activeTabItem;
|
||||||
@@ -150,7 +149,7 @@
|
|||||||
// maybe not the most robust things, not super reusable cuz it depends on outside vars but works for now...
|
// 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('declined friend request, now response')
|
||||||
console.log({...resp})
|
console.log({...resp})
|
||||||
await fetchFriendshipFull(userIdBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
};
|
};
|
||||||
|
|
||||||
const unfriend = async(relationshipId) => {
|
const unfriend = async(relationshipId) => {
|
||||||
@@ -161,7 +160,7 @@
|
|||||||
|
|
||||||
// friendshipStatusFull = undefined;
|
// friendshipStatusFull = undefined;
|
||||||
// OR
|
// OR
|
||||||
await fetchFriendshipFull(userIdBeingViewed);
|
await fetchFriendshipFull(usernameBeingViewed);
|
||||||
if (Object.keys(friendshipStatusFull).length === 0)
|
if (Object.keys(friendshipStatusFull).length === 0)
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
@@ -178,14 +177,14 @@
|
|||||||
headers: { 'Content-Type': 'application/json'},
|
headers: { 'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"receiverUsername": aUser.username,
|
"receiverUsername": aUser.username,
|
||||||
"receiverId": aUser.id,
|
"receiverId": aUser.username,
|
||||||
"status": "B"
|
"status": "B"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then( x => x.json())
|
.then( x => x.json())
|
||||||
await fetchBlockedUsers();
|
await fetchBlockedUsers();
|
||||||
await fetchAllUsers();
|
await fetchAllUsers();
|
||||||
userIdBeingViewed = undefined;
|
usernameBeingViewed = undefined;
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
// will this make it reload?
|
// will this make it reload?
|
||||||
@@ -201,7 +200,7 @@
|
|||||||
console.log({...resp})
|
console.log({...resp})
|
||||||
await fetchBlockedUsers();
|
await fetchBlockedUsers();
|
||||||
await fetchAllUsers();
|
await fetchAllUsers();
|
||||||
userIdBeingViewed = undefined;
|
usernameBeingViewed = undefined;
|
||||||
friendshipStatusFull = undefined;
|
friendshipStatusFull = undefined;
|
||||||
|
|
||||||
// will this make it reload?
|
// will this make it reload?
|
||||||
@@ -252,9 +251,9 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<!-- does this work? -->
|
<!-- does this work? -->
|
||||||
<!-- {#each allUsers as aUser (aUser.username)} -->
|
<!-- {#each allUsers as aUser (aUser.username)} -->
|
||||||
<!-- {#each allUsers as aUser} -->
|
<!-- {#each allUsers as aUser (aUser.id)} -->
|
||||||
{#each allUsers as aUser (aUser.id)}
|
{#each allUsers as aUser}
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aUser.id)}>{aUser.username}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
|
||||||
<!-- i could make an indicator component? like green for connected or something?
|
<!-- i could make an indicator component? like green for connected or something?
|
||||||
i could use words but color them?
|
i could use words but color them?
|
||||||
i could make it so if they're in a game -->
|
i could make it so if they're in a game -->
|
||||||
@@ -268,7 +267,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<!-- {#each myFriends as aUser (aUser.id)} -->
|
<!-- {#each myFriends as aUser (aUser.id)} -->
|
||||||
{#each myFriends as aUser}
|
{#each myFriends as aUser}
|
||||||
<div class="sidebar-item" on:click={() => viewAUser(aUser.id)}>{aUser.username}</div>
|
<div class="sidebar-item" on:click={() => viewAUser(aUser.username)}>{aUser.username}</div>
|
||||||
<div class="status sidebar-item">{aUser.status}</div>
|
<div class="status sidebar-item">{aUser.status}</div>
|
||||||
<br>
|
<br>
|
||||||
{/each}
|
{/each}
|
||||||
@@ -300,9 +299,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="main-display">
|
<div class="main-display">
|
||||||
{#if userIdBeingViewed !== undefined}
|
{#if usernameBeingViewed !== undefined}
|
||||||
<!-- <DisplayAUser aUsername={usernameBeingViewed}/> -->
|
<!-- <DisplayAUser aUsername={usernameBeingViewed}/> -->
|
||||||
<DisplayAUser aUserId={userIdBeingViewed}/>
|
<DisplayAUser aUsername={usernameBeingViewed}/>
|
||||||
|
|
||||||
<div class="buttons-area">
|
<div class="buttons-area">
|
||||||
{#if friendshipStatusFull && friendshipStatusFull.id}
|
{#if friendshipStatusFull && friendshipStatusFull.id}
|
||||||
@@ -333,8 +332,8 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<Button type="secondary" on:click={() => sendFriendRequest(userIdBeingViewed)}>Add Friend</Button>
|
<Button type="secondary" on:click={() => sendFriendRequest(usernameBeingViewed)}>Add Friend</Button>
|
||||||
<Button on:click={() => blockANonFriendUser(userIdBeingViewed)}>Block User</Button>
|
<Button on:click={() => blockANonFriendUser(usernameBeingViewed)}>Block User</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -4,14 +4,14 @@
|
|||||||
import GenerateUserDisplay from './GenerateUserDisplay.svelte';
|
import GenerateUserDisplay from './GenerateUserDisplay.svelte';
|
||||||
|
|
||||||
// export let aUsername;
|
// export let aUsername;
|
||||||
export let aUserId;
|
export let aUsername;
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
// console.log('Display aUser username: '+ aUsername)
|
// console.log('Display aUser username: '+ aUsername)
|
||||||
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
||||||
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
||||||
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUserId}`)
|
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
|
|
||||||
// console.log('Display a user: ')
|
// console.log('Display a user: ')
|
||||||
@@ -32,12 +32,12 @@
|
|||||||
// console.log('Display Update aUser username: '+ aUsername)
|
// console.log('Display Update aUser username: '+ aUsername)
|
||||||
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
// http://transcendance:8080/api/v2/user?username=NomDuUserATrouver
|
||||||
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
// user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
||||||
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUserId}`)
|
user = await fetch(`http://transcendance:8080/api/v2/user?id=${aUsername}`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
};
|
};
|
||||||
|
|
||||||
// $: aUsername, updateUser();
|
// $: aUsername, updateUser();
|
||||||
$: aUserId, updateUser();
|
$: aUsername, updateUser();
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
<!-- <GenerateUserDisplay user={user} primary={true}/> -->
|
<!-- <GenerateUserDisplay user={user} primary={true}/> -->
|
||||||
{:else}
|
{:else}
|
||||||
<h2>Sorry</h2>
|
<h2>Sorry</h2>
|
||||||
<div>Failed to load user {aUserId}</div>
|
<div>Failed to load user {aUsername}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user