cleaned up friendship module in backend, still haven't tested blocking feature
This commit is contained in:
@@ -18,20 +18,7 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.findAllFriends(user.id);
|
return this.friendshipService.findAllFriends(user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the username may change but the relationship id will not so we need to grab the relationship id from the username
|
// GET http://transcendance:8080/api/v2/network/:friendUsername
|
||||||
// ie did that username send a friendship thing, and if so what are the ids
|
|
||||||
|
|
||||||
|
|
||||||
// GET http://transcendance:8080/api/v2/network/myfriends/relationshipId
|
|
||||||
// @Get('myfriend/:relationshipId')
|
|
||||||
// @UseGuards(AuthenticateGuard)
|
|
||||||
// @UseGuards(TwoFactorGuard)
|
|
||||||
// findOneFriend(@Param('relationshipId') relationshipId: string, @Req() req) {
|
|
||||||
// console.log("Username " + relationshipId);
|
|
||||||
// const user = req.user;
|
|
||||||
// return this.friendshipService.findOneFriend(relationshipId, user.username);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Get('myfriends/:friendUsername')
|
@Get('myfriends/:friendUsername')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@@ -82,19 +69,6 @@ export class FriendshipController {
|
|||||||
return this.friendshipService.acceptFriendship(relationshipId, user);
|
return this.friendshipService.acceptFriendship(relationshipId, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TEST !!!!!!!!!!
|
|
||||||
@Get('myfriends/:relationshipId/test')
|
|
||||||
@UseGuards(AuthenticateGuard)
|
|
||||||
@UseGuards(TwoFactorGuard)
|
|
||||||
test(@Param('relationshipId') relationshipId: string, @Req() req)
|
|
||||||
{
|
|
||||||
const user : User = req.user;
|
|
||||||
console.log('testing a friendship MMMMMMMMMMMMMMMMM')
|
|
||||||
return this.friendshipService.testFriendship(relationshipId, user);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Patch('myfriends/:relationshipId/decline')
|
@Patch('myfriends/:relationshipId/decline')
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
|
|||||||
@@ -15,17 +15,8 @@ export class FriendshipService {
|
|||||||
private readonly userRepository: Repository<User>,
|
private readonly userRepository: Repository<User>,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
|
|
||||||
async findOneFriend(friendshipId: string, username: string) {
|
|
||||||
const friendship = await this.friendshipRepository.find({ where: { id: +friendshipId, senderUsername: username, status: FriendshipStatus.ACCEPTED } });
|
|
||||||
if (!friendship)
|
|
||||||
throw new HttpException(`The requested friend not found.`, HttpStatus.NOT_FOUND);
|
|
||||||
return friendship;
|
|
||||||
}
|
|
||||||
|
|
||||||
async findOneFriendByUsername(friendUsername : string, username : string) {
|
async findOneFriendByUsername(friendUsername : string, username : string) {
|
||||||
// const friendship = await this.friendshipRepository
|
const friendship = await this.friendshipRepository
|
||||||
let friendship = await this.friendshipRepository
|
|
||||||
.createQueryBuilder('friendship')
|
.createQueryBuilder('friendship')
|
||||||
.where(
|
.where(
|
||||||
new Brackets((qb) => {
|
new Brackets((qb) => {
|
||||||
@@ -51,38 +42,6 @@ export class FriendshipService {
|
|||||||
)
|
)
|
||||||
.getOne()
|
.getOne()
|
||||||
|
|
||||||
// console.log('MIDDLE Find one friend by username: ')
|
|
||||||
// console.log({...friendship})
|
|
||||||
|
|
||||||
// if (!friendship) {
|
|
||||||
// friendship = await this.friendshipRepository
|
|
||||||
// .createQueryBuilder('friendship')
|
|
||||||
// .where(
|
|
||||||
// new Brackets((qb) => {
|
|
||||||
// qb.where(
|
|
||||||
// new Brackets((subAQb) => {
|
|
||||||
// subAQb.where('friendship.senderUsername = :username', {username : username})
|
|
||||||
// .andWhere('friendship.receiverUsername = :friendUsername', {friendUsername : friendUsername})
|
|
||||||
// })
|
|
||||||
// )
|
|
||||||
// .orWhere(
|
|
||||||
// new Brackets((subBQb) => {
|
|
||||||
// subBQb.where('friendship.senderUsername = :friendUsername', {friendUsername : friendUsername})
|
|
||||||
// .andWhere('friendship.receiverUsername = :username', {username : username})
|
|
||||||
// })
|
|
||||||
// )
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
// .andWhere(
|
|
||||||
// new Brackets((qb2) => {
|
|
||||||
// // qb2.where('friendship.status = :status', {status : FriendshipStatus.ACCEPTED})
|
|
||||||
// // .orWhere('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
|
|
||||||
// qb2.where('friendship.status = :status', {status : FriendshipStatus.REQUESTED})
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
// .getOne()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// console.log('END Find one friend by username: ')
|
// console.log('END Find one friend by username: ')
|
||||||
// console.log({...friendship})
|
// console.log({...friendship})
|
||||||
|
|
||||||
@@ -203,115 +162,16 @@ export class FriendshipService {
|
|||||||
return partialFriendship;
|
return partialFriendship;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
'0': Friendship {
|
|
||||||
id: 1,
|
|
||||||
date: 2022-12-15T03:00:05.134Z,
|
|
||||||
senderUsername: 'chbadad',
|
|
||||||
receiverUsername: 'erlazo',
|
|
||||||
status: 'R',
|
|
||||||
sender: User {
|
|
||||||
id: 2,
|
|
||||||
fortyTwoId: '84193',
|
|
||||||
username: 'chbadad',
|
|
||||||
email: 'chbadad@student.42.fr',
|
|
||||||
image_url: 'default.png',
|
|
||||||
phone: null,
|
|
||||||
status: 'connected',
|
|
||||||
isEnabledTwoFactorAuth: false,
|
|
||||||
isTwoFactorAuthenticated: false,
|
|
||||||
secretTwoFactorAuth: null
|
|
||||||
},
|
|
||||||
receiver: User {
|
|
||||||
id: 1,
|
|
||||||
fortyTwoId: '40588',
|
|
||||||
username: 'erlazo',
|
|
||||||
email: 'erlazo@student.42.fr',
|
|
||||||
image_url: 'default.png',
|
|
||||||
phone: null,
|
|
||||||
status: 'connected',
|
|
||||||
isEnabledTwoFactorAuth: false,
|
|
||||||
isTwoFactorAuthenticated: false,
|
|
||||||
secretTwoFactorAuth: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VS ------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
id: 1,
|
|
||||||
date: 2022-12-15T03:00:05.134Z,
|
|
||||||
senderUsername: 'chbadad',
|
|
||||||
receiverUsername: 'erlazo',
|
|
||||||
status: 'R',
|
|
||||||
sender: User {
|
|
||||||
id: 2,
|
|
||||||
fortyTwoId: '84193',
|
|
||||||
username: 'chbadad',
|
|
||||||
email: 'chbadad@student.42.fr',
|
|
||||||
image_url: 'default.png',
|
|
||||||
phone: null,
|
|
||||||
status: 'connected',
|
|
||||||
isEnabledTwoFactorAuth: false,
|
|
||||||
isTwoFactorAuthenticated: false,
|
|
||||||
secretTwoFactorAuth: null
|
|
||||||
},
|
|
||||||
receiver: User {
|
|
||||||
id: 1,
|
|
||||||
fortyTwoId: '40588',
|
|
||||||
username: 'erlazo',
|
|
||||||
email: 'erlazo@student.42.fr',
|
|
||||||
image_url: 'default.png',
|
|
||||||
phone: null,
|
|
||||||
status: 'connected',
|
|
||||||
isEnabledTwoFactorAuth: false,
|
|
||||||
isTwoFactorAuthenticated: false,
|
|
||||||
secretTwoFactorAuth: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TEST !!!!!!!!!
|
|
||||||
async testFriendship(relationshipId: string, user: User) {
|
|
||||||
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
|
||||||
// const relation = await this.friendshipRepository.find({take: 1, where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
|
||||||
// const relation = await this.friendshipRepository.find({select: {0: Friendship}, where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
|
||||||
// const relation = await this.friendshipRepository.findOne({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
|
|
||||||
|
|
||||||
console.log('.service test friendship')
|
|
||||||
console.log({...relation})
|
|
||||||
if (relation[0].sender.id) {
|
|
||||||
console.log('it worked!')
|
|
||||||
}
|
|
||||||
if (!relation) {
|
|
||||||
throw new HttpException(`Found NOTHING.`, HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
return relation;
|
|
||||||
}
|
|
||||||
|
|
||||||
async acceptFriendship(relationshipId: string, user: User) {
|
async acceptFriendship(relationshipId: string, user: User) {
|
||||||
// const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
|
||||||
// ok gotta swap out hte findOneBy for a find, recall what you did in the Nest.js tutorial
|
|
||||||
// this is what i want ideally...
|
|
||||||
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
||||||
// const relation = await this.friendshipRepository.findOneBy({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
|
// console.log('.service accept friendship')
|
||||||
// const relation = await this.friendshipRepository.findOne({where: {id: +relationshipId }, relations: ['sender', 'receiver']});
|
// console.log({...relation})
|
||||||
|
|
||||||
console.log('.service accept friendship')
|
|
||||||
console.log({...relation})
|
|
||||||
if (!relation[0])
|
if (!relation[0])
|
||||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
||||||
// console.log(relation.sender)
|
|
||||||
// ok so you can't query sender cuz it's not a column in the entity, not sure how you access it then...
|
|
||||||
// if (relation.sender.id === user.id) {
|
|
||||||
if (relation[0].sender.id === user.id) {
|
if (relation[0].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[0].status = FriendshipStatus.ACCEPTED;
|
relation[0].status = FriendshipStatus.ACCEPTED;
|
||||||
// are we sure saving relation[0] won't fuck things up? cuz aren't there 2 User in there?
|
|
||||||
// should i partial friendship intermediary first?
|
|
||||||
const savedFriendship = this.friendshipRepository.save(relation[0]);
|
const savedFriendship = this.friendshipRepository.save(relation[0]);
|
||||||
const partialFriendship : Partial<Friendship> = {
|
const partialFriendship : Partial<Friendship> = {
|
||||||
id : (await savedFriendship).id,
|
id : (await savedFriendship).id,
|
||||||
@@ -326,7 +186,6 @@ VS ------------------------------------------------
|
|||||||
}
|
}
|
||||||
|
|
||||||
async declineFriendship(relationshipId: string, user: User) {
|
async declineFriendship(relationshipId: string, user: User) {
|
||||||
// const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
|
||||||
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
||||||
if (!relation[0])
|
if (!relation[0])
|
||||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
||||||
@@ -345,7 +204,6 @@ VS ------------------------------------------------
|
|||||||
}
|
}
|
||||||
|
|
||||||
async blockFriendship(relationshipId: string, user: User) {
|
async blockFriendship(relationshipId: string, user: User) {
|
||||||
// const relation = await this.friendshipRepository.findOneBy({ id: +relationshipId });
|
|
||||||
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
const relation = await this.friendshipRepository.find({where: {id: +relationshipId }, relations: ['sender', 'receiver']} );
|
||||||
if (!relation[0])
|
if (!relation[0])
|
||||||
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { get } from "svelte/store";
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
|
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user