ok so i fixed the get user by username issue, left all the comments in the back so Cherif and I can go over what i changed just to make sure i didn't break something else, but yea that and my front work just fine
This commit is contained in:
@@ -36,7 +36,9 @@ 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;
|
||||||
console.log(`User id: ${user.id}\nFriend id: ${createFriendshipDto.requesterUsername}\nStatus: ${createFriendshipDto.status}`);
|
|
||||||
|
console.log(`User id: ${user.id}\nUser name: ${createFriendshipDto.requesterUsername}\nStatus: ${createFriendshipDto.status}`);
|
||||||
|
|
||||||
if (user.username === createFriendshipDto.requesterUsername)
|
if (user.username === createFriendshipDto.requesterUsername)
|
||||||
return this.friendshipService.create(createFriendshipDto, user);
|
return this.friendshipService.create(createFriendshipDto, user);
|
||||||
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
|
return new HttpException('You can\'t request a frienship for another user', HttpStatus.FORBIDDEN);
|
||||||
@@ -77,7 +79,7 @@ export class FriendshipController {
|
|||||||
findAllPendantFriendshipRequested(@Req() req) {
|
findAllPendantFriendshipRequested(@Req() req) {
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
|
|
||||||
console.log("WHAT IS UP MY GUYS IT IS YOUR BOI THAT IDIOT YOU HATE Pending 33333");
|
// console.log("WHAT IS UP MY GUYS IT IS YOUR BOI THAT IDIOT YOU HATE Pending 33333");
|
||||||
|
|
||||||
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
|
return this.friendshipService.findAllPendantRequestsForFriendship(user.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,14 +69,24 @@ export class FriendshipService {
|
|||||||
//GROS CHANTIER
|
//GROS CHANTIER
|
||||||
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
|
async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
|
||||||
const addressee = await this.userRepository.findOneBy({username: createFriendshipDto.addresseeUsername});
|
const addressee = await this.userRepository.findOneBy({username: createFriendshipDto.addresseeUsername});
|
||||||
|
|
||||||
|
console.log('made it to create friendship from friendship controller')
|
||||||
|
|
||||||
if (!addressee)
|
if (!addressee)
|
||||||
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
||||||
// console.log('Addressee ID: ' + addressee.id + 'Username: ' + a)
|
console.log('Addressee ID: ' + addressee.id + ' Username: ' + addressee.username)
|
||||||
|
console.log('Creator ID: ' + creator.id + ' Username: ' + creator.username)
|
||||||
if (creator.id === addressee.id)
|
if (creator.id === addressee.id)
|
||||||
throw new HttpException(`You can't add yourself.`, HttpStatus.FORBIDDEN);
|
throw new HttpException(`You can't add yourself.`, HttpStatus.FORBIDDEN);
|
||||||
|
console.log('test 1')
|
||||||
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
|
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
|
||||||
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
||||||
|
console.log('test 2')
|
||||||
|
|
||||||
const friendship = await this.friendshipRepository.findOneBy({ requesterUsername: createFriendshipDto.requesterUsername, addresseeUsername: createFriendshipDto.addresseeUsername });
|
const friendship = await this.friendshipRepository.findOneBy({ requesterUsername: createFriendshipDto.requesterUsername, addresseeUsername: createFriendshipDto.addresseeUsername });
|
||||||
|
|
||||||
|
console.log('test 3')
|
||||||
|
|
||||||
if (friendship) {
|
if (friendship) {
|
||||||
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
|
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
|
||||||
throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
|
throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
|
||||||
@@ -87,8 +97,17 @@ export class FriendshipService {
|
|||||||
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
|
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
|
||||||
throw new HttpException(`The request has been declined.`, HttpStatus.OK);
|
throw new HttpException(`The request has been declined.`, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
console.log('test 7')
|
||||||
|
|
||||||
const newFriendship = this.friendshipRepository.create(createFriendshipDto);
|
const newFriendship = this.friendshipRepository.create(createFriendshipDto);
|
||||||
return this.friendshipRepository.save(newFriendship);
|
console.log('test 8, New Friendship: ')
|
||||||
|
console.log({...newFriendship})
|
||||||
|
|
||||||
|
const tmp = this.friendshipRepository.save(newFriendship);
|
||||||
|
console.log('tmp: ')
|
||||||
|
console.log({...tmp})
|
||||||
|
return tmp;
|
||||||
|
// return this.friendshipRepository.save(newFriendship);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateFriendship(relationshipId: string, user: User, status: string) {
|
async updateFriendship(relationshipId: string, user: User, status: string) {
|
||||||
@@ -119,14 +138,20 @@ export class FriendshipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findIfUserIsBlockedOrHasBlocked(userConnectedId: string, userToCheckId: string) {
|
async findIfUserIsBlockedOrHasBlocked(userConnectedId: string, userToCheckId: string) {
|
||||||
|
console.log("finding if user is blocked")
|
||||||
const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.where('friendship.requesterUsername = :requestee', { requestee: userConnectedId })
|
.where('friendship.requesterUsername = :requestee', { requestee: userConnectedId })
|
||||||
.orWhere('friendship.requesterUsername = :requesteeBis', { requesteeBis: userToCheckId })
|
.orWhere('friendship.requesterUsername = :requesteeBis', { requesteeBis: userToCheckId })
|
||||||
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
|
||||||
.getOne();
|
.getOne();
|
||||||
if (friendship)
|
console.log("printing friendship")
|
||||||
|
console.log(friendship)
|
||||||
|
// console.log({...friendship})
|
||||||
|
if (friendship) {
|
||||||
|
console.log('we are blocked in friendship.service')
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,12 +36,26 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// @UseGuards(AuthenticateGuard)
|
||||||
|
// @UseGuards(TwoFactorGuard)
|
||||||
|
// @Get()
|
||||||
|
// findOne(@Req() req) {
|
||||||
|
// console.log("Backend Getting current user");
|
||||||
|
// return this.usersService.findOne(req.user.id);
|
||||||
|
// }
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get()
|
@Get()
|
||||||
findOne(@Req() req) {
|
findOne(@Query('username') username: string, @Req() req) {
|
||||||
console.log("Backend Getting current user");
|
if (username === undefined) {
|
||||||
return this.usersService.findOne(req.user.id);
|
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: ' + username)
|
||||||
|
return this.usersService.findOneByUsername(user.id.toString(),username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET http://transcendance:8080/user?username=NomDuUser
|
// GET http://transcendance:8080/user?username=NomDuUser
|
||||||
@@ -54,6 +68,7 @@ export class UsersController {
|
|||||||
return this.usersService.findOneByUsername(user.id.toString(),username);
|
return this.usersService.findOneByUsername(user.id.toString(),username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get('stats')
|
@Get('stats')
|
||||||
|
|||||||
@@ -66,10 +66,20 @@ export class UsersService {
|
|||||||
.where('user.username = :username', { username: username })
|
.where('user.username = :username', { username: username })
|
||||||
.getOne();
|
.getOne();
|
||||||
console.log('USERNAME OF FOUND USER : ' + user.username);
|
console.log('USERNAME OF FOUND USER : ' + user.username);
|
||||||
|
// console.log({...user})
|
||||||
|
// you can't do that, you need to do user === undefined
|
||||||
|
// if (user === undefined)
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user could not be found 1.`,HttpStatus.NOT_FOUND);
|
||||||
if (this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString()))
|
|
||||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString())
|
||||||
|
console.log('printing return of checking if blocked')
|
||||||
|
console.log(tmp)
|
||||||
|
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(userConnectedId, user.id.toString())) {
|
||||||
|
console.log('we are blocked in user.service')
|
||||||
|
throw new HttpException(`The user could not be found 2.`,HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
const partialUser : Partial<User> = {
|
const partialUser : Partial<User> = {
|
||||||
username: user.username,
|
username: user.username,
|
||||||
image_url: user.image_url,
|
image_url: user.image_url,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ could be a list of friends and if they're active but i can't see that yet
|
|||||||
let myFriends;
|
let myFriends;
|
||||||
let requestsMade, requestsRecieved;
|
let requestsMade, requestsRecieved;
|
||||||
let allUsers;
|
let allUsers;
|
||||||
let allFriends;
|
|
||||||
let userToDisplay;
|
let userToDisplay;
|
||||||
|
|
||||||
|
|
||||||
@@ -40,89 +39,91 @@ could be a list of friends and if they're active but i can't see that yet
|
|||||||
user = await fetch('http://transcendance:8080/api/v2/user')
|
user = await fetch('http://transcendance:8080/api/v2/user')
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
|
|
||||||
console.log('user is ')
|
// console.log('user is ')
|
||||||
console.log(user)
|
// console.log(user)
|
||||||
console.log(user.username)
|
// console.log(user.username)
|
||||||
|
|
||||||
myFriends = await fetch("http://transcendance:8080/api/v2/network/myfriends")
|
myFriends = await fetch("http://transcendance:8080/api/v2/network/myfriends")
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
|
|
||||||
console.log('my friends')
|
// console.log('my friends')
|
||||||
console.log(myFriends)
|
// console.log(myFriends)
|
||||||
|
|
||||||
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('Requests pending ');
|
// console.log('Requests pending ');
|
||||||
console.log(requestsMade);
|
// console.log(requestsMade);
|
||||||
|
|
||||||
|
|
||||||
requestsRecieved = await fetch('http://transcendance:8080/api/v2/network/received')
|
requestsRecieved = await fetch('http://transcendance:8080/api/v2/network/received')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
|
|
||||||
console.log('Requests received ');
|
// console.log('Requests received ');
|
||||||
console.log(requestsRecieved);
|
// console.log(requestsRecieved);
|
||||||
|
|
||||||
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got all users ' + allUsers)
|
// console.log('got all users ' + allUsers)
|
||||||
|
|
||||||
allFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
|
|
||||||
.then( x => x.json() );
|
|
||||||
console.log('got all friends ' + allFriends)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const displayAllUsers = async() => {
|
const displayAllUsers = async() => {
|
||||||
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
allUsers = await fetch('http://transcendance:8080/api/v2/user/all')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got all users ' + allUsers)
|
// console.log('got all users ' + allUsers)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const displayAllFriends = async() => {
|
const displayAllFriends = async() => {
|
||||||
allFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
|
myFriends = await fetch('http://transcendance:8080/api/v2/network/myfriends')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got all friends ' + allFriends)
|
// console.log('got all friends ' + allFriends)
|
||||||
};
|
};
|
||||||
|
|
||||||
const displayRequestsMade = async() => {
|
const displayRequestsMade = async() => {
|
||||||
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
requestsMade = await fetch('http://transcendance:8080/api/v2/network/pending')
|
||||||
.then( x => x.json() );
|
.then( x => x.json() );
|
||||||
console.log('got requests made ' + requestsMade)
|
// console.log('got requests made ' + requestsMade)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// const sendFriendRequest =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let sentFriendRequest;
|
let sentFriendRequest;
|
||||||
const friendUserByUsername = async(potenticalFriendUsername) => {
|
// const friendUserByUsername = async(potenticalFriendUsername) => {
|
||||||
|
const friendUserByUsername = async() => {
|
||||||
let valid = false;
|
let valid = false;
|
||||||
|
|
||||||
if (potenticalFriendUsername === '' || potenticalFriendUsername.trim() === '') {
|
if (!user || !user.username) {
|
||||||
|
valid = false;
|
||||||
|
}
|
||||||
|
// if (potenticalFriendUsername === '' || potenticalFriendUsername.trim() === '') {
|
||||||
|
if (set.friendUsername === '' || set.friendUsername.trim() === '') {
|
||||||
errors.friendRequest = "You have to put a friend's name in.";
|
errors.friendRequest = "You have to put a friend's name in.";
|
||||||
valid = false;
|
valid = false;
|
||||||
} else if (potenticalFriendUsername === user.username) {
|
} else if (set.friendUsername === user.username) {
|
||||||
errors.friendRequest = "You can't friend yourself."
|
errors.friendRequest = "You can't friend yourself."
|
||||||
valid = false;
|
valid = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
if (!user || !user.username) {
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// should i be checking if a Friend request has already been made ?
|
// should i be checking if a Friend request has already been made ?
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let r = "R";
|
|
||||||
|
|
||||||
console.log('user is ')
|
console.log('user is ')
|
||||||
console.log(user)
|
console.log(user)
|
||||||
console.log(user.username)
|
console.log(user.username)
|
||||||
console.log('friend is ')
|
console.log('friend is ')
|
||||||
console.log(set.friendUsername)
|
console.log(set.friendUsername)
|
||||||
|
|
||||||
set.friendId = allUsers.find(f => f.username === set.friendUsername).id
|
// set.friendId = allUsers.find(f => f.username === set.friendUsername).id
|
||||||
console.log('friend found: ' + set.friendId)
|
// console.log('friend found: ' + set.friendId)
|
||||||
|
|
||||||
// ok this version works
|
// ok this version works
|
||||||
// ok not really, requesterId and all that is good but...
|
// ok not really, requesterId and all that is good but...
|
||||||
@@ -137,7 +138,7 @@ could be a list of friends and if they're active but i can't see that yet
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then( x => x.json())
|
.then( x => x.json())
|
||||||
.then (x => console.log({...x}));
|
// .then (x => console.log({...x}));
|
||||||
|
|
||||||
// should i then update requtestsMade with another fetch?
|
// should i then update requtestsMade with another fetch?
|
||||||
// maybe also check if the request went through?
|
// maybe also check if the request went through?
|
||||||
@@ -159,6 +160,10 @@ could be a list of friends and if they're active but i can't see that yet
|
|||||||
{:else}
|
{:else}
|
||||||
<!-- problem, i can't use user.id since Cherif doesn't want to expost that to the front...
|
<!-- problem, i can't use user.id since Cherif doesn't want to expost that to the front...
|
||||||
is there something else i could use? -->
|
is there something else i could use? -->
|
||||||
|
<!-- add a thing so it doesn't display the current user just all the other users -->
|
||||||
|
|
||||||
|
<!-- does this work? -->
|
||||||
|
<!-- {#each allUsers as aUser (aUser.username)} -->
|
||||||
{#each allUsers as aUser }
|
{#each allUsers as aUser }
|
||||||
<!-- <div class="a-user" on:click={() => displayAUser(aUser.username)}>{aUser.username}</div> -->
|
<!-- <div class="a-user" on:click={() => displayAUser(aUser.username)}>{aUser.username}</div> -->
|
||||||
<div class="a-user" on:click={() => userToDisplay = aUser.username}>{aUser.username}</div>
|
<div class="a-user" on:click={() => userToDisplay = aUser.username}>{aUser.username}</div>
|
||||||
@@ -199,22 +204,23 @@ could be a list of friends and if they're active but i can't see that yet
|
|||||||
|
|
||||||
<br> -->
|
<br> -->
|
||||||
|
|
||||||
<!-- <Button on:click={displayAllFriends}>Get All Friends</Button>
|
<!-- <Button on:click={displayMyFriends}>Get All My Friends</Button>
|
||||||
{#if allFriends !== undefined}
|
{#if myFriends !== undefined}
|
||||||
<div>{allFriends}</div>
|
<div>{myFriends}</div>
|
||||||
{#each allFriends as friend}
|
{#each myFriends as friend}
|
||||||
<div>{friend}{friend.username}</div>
|
<div>{friend}{friend.username}</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if} -->
|
{/if} -->
|
||||||
|
|
||||||
<!-- <br>
|
<br>
|
||||||
|
|
||||||
<div>Make a Friend!</div>
|
<div>Make a Friend!</div>
|
||||||
<form on:submit|preventDefault={() => friendUserByUsername(set.friendUsername)}>
|
<!-- <form on:submit|preventDefault={() => friendUserByUsername(set.friendUsername)}> -->
|
||||||
|
<form on:submit|preventDefault={friendUserByUsername}>
|
||||||
<input type="text" placeholder="friend's username" bind:value={set.friendUsername}>
|
<input type="text" placeholder="friend's username" bind:value={set.friendUsername}>
|
||||||
<div class="error">{errors.friendRequest}</div>
|
<div class="error">{errors.friendRequest}</div>
|
||||||
<Button type="secondary">Send Friend Request</Button>
|
<Button type="secondary">Send Friend Request</Button>
|
||||||
</form> -->
|
</form>
|
||||||
|
|
||||||
<!-- <br> <br> -->
|
<!-- <br> <br> -->
|
||||||
<!-- here i want to list all the requests you and have an accept and a decline button -->
|
<!-- here i want to list all the requests you and have an accept and a decline button -->
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
user = await fetch(`http://transcendance:8080/api/v2/user?username=${aUsername}`)
|
||||||
.then( (x) => x.json() );
|
.then( (x) => x.json() );
|
||||||
|
|
||||||
console.log('Display a user: ' + user.username)
|
// console.log('Display a user: ')
|
||||||
|
// console.log({...user})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user