From 3b7207966354904ef6e95fd413770c86573896c8 Mon Sep 17 00:00:00 2001 From: Me Date: Tue, 17 Jan 2023 21:29:41 +0100 Subject: [PATCH] cleaned up everything, basically all comments and console.logs are gone --- .../src/friendship/friendship.controller.ts | 9 --- .../src/friendship/friendship.service.ts | 63 +------------------ .../src/friendship/sendableFriendship.ts | 6 -- .../api_back/src/users/sendableUsers.ts | 1 - .../api_back/src/users/users.service.ts | 29 +-------- .../src/pages/TwoFactorAuthentication.svelte | 9 --- .../profile/ProfileDisplayOneUser.svelte | 15 ++--- .../src/pages/profile/ProfileSettings.svelte | 29 +-------- .../src/pages/profile/ProfileUsers.svelte | 6 -- .../svelte/api_front/src/pieces/Card.svelte | 2 - .../src/pieces/GenerateUserDisplay.svelte | 16 ----- .../svelte/api_front/src/pieces/Header.svelte | 5 -- .../svelte/api_front/src/pieces/Tabs.svelte | 8 --- .../svelte/api_front/src/pieces/utils.ts | 1 - .../api_front/src/routes/primaryRoutes.js | 2 - .../api_front/src/routes/profileRoutes.js | 3 - 16 files changed, 10 insertions(+), 194 deletions(-) diff --git a/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts b/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts index 641ec46a..37d8ea1e 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.controller.ts @@ -8,17 +8,13 @@ import { FriendshipService } from './friendship.service'; export class FriendshipController { constructor(private readonly friendshipService: FriendshipService) { } - - // new and improved finder of people // GET http://transcendance:8080/api/v2/network/myfriends @Get('myfriends') @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) findOne(@Query('username') otherUsername: string, @Req() req) { - // console.log('GET myfriends') const user = req.user; if (otherUsername !== undefined) { - // console.log('my friend: ' + otherUsername) return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username); } return this.friendshipService.findAllFriendships(user.id); @@ -30,10 +26,8 @@ export class FriendshipController { @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) { - // console.log('friendship.service create') const user = req.user; if (user.username !== createFriendshipDto.receiverUsername) { - // console.log('friendship.service create have a receiver name') return this.friendshipService.create(createFriendshipDto, user); } return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST); @@ -72,7 +66,6 @@ export class FriendshipController { @UseGuards(TwoFactorGuard) remove(@Param('relationshipId') relationshipId: number, @Req() req) { const user : User = req.user; - // console.log('deleting a friendship') return this.friendshipService.removeFriendship(relationshipId, user); } @@ -99,8 +92,6 @@ export class FriendshipController { @UseGuards(AuthenticateGuard) @UseGuards(TwoFactorGuard) findBlocked(@Query('relationshipId') relationshipId: number, @Req() req) { - // console.log('friendship.controller fetching blocked users') - // console.log(relationshipId) const user = req.user; if (Number.isNaN(relationshipId)) return this.friendshipService.findAllBlockedFriends(user.id); diff --git a/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts b/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts index d0aba0ab..17cba491 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/friendship.service.ts @@ -16,7 +16,6 @@ export class FriendshipService { private readonly userRepository: Repository, ) { } - //kinda useless but someone else might use it async findOneRelationshipById(friendId : number, userId : number) { const friendship = await this.friendshipRepository .createQueryBuilder('friendship') @@ -39,12 +38,8 @@ export class FriendshipService { ) }), ) - // .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED}) .getOne() - // console.log('END Find one friend by ID: ') - // console.log({...friendship}) - if (!friendship) { throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND); } @@ -52,7 +47,6 @@ export class FriendshipService { } async findOneRelationshipByUsername(friendUsername : string, username : string) { - // This seems to work, finding friendships by username but checking the actual users not the friendship const friendship = await this.friendshipRepository .createQueryBuilder('friendship') .leftJoinAndSelect('friendship.sender', 'sender') @@ -76,9 +70,6 @@ export class FriendshipService { ) .getOne() - // console.log('END Find one friend by username: ') - // console.log({...friendship}) - if (!friendship) { throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND); } @@ -100,8 +91,6 @@ export class FriendshipService { for (const friendship of friendships) { sendFrienships.push(new SendableFriendship(friendship)); } - // console.log('friendship.service my friends:') - // console.log({...sendFrienships}) return sendFrienships; } @@ -142,16 +131,6 @@ export class FriendshipService { .where('sender.id = :requestee', { requestee: userId }) .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED }) .getMany(); - - // let partialFriendship : Partial[] = []; - // for (const friendship of friendships) { - // 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({...friendships}) - // console.log('friendship.service findAllBlockedFriends, partial friendship:') - // return partialFriendship; - let sendFrienships: SendableFriendship[] = [] for (const friendship of friendships) { sendFrienships.push(new SendableFriendship(friendship)); @@ -167,10 +146,6 @@ export class FriendshipService { .where('sender.id = :requestee', { requestee: userId }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .getMany(); - - // console.log('friendships services pendant friendships:') - // console.log({...friendships}) - let sendFrienships: SendableFriendship[] = [] for (const friendship of friendships) { sendFrienships.push(new SendableFriendship(friendship)); @@ -186,10 +161,6 @@ export class FriendshipService { .where('receiver.id = :addressee', { addressee: userId }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .getMany(); - - // console.log('friendship service received requests') - // console.log({...friendships}) - let sendFrienships: SendableFriendship[] = [] for (const friendship of friendships) { sendFrienships.push(new SendableFriendship(friendship)); @@ -198,15 +169,11 @@ export class FriendshipService { } async create(createFriendshipDto: CreateFriendshipDto, creator : User) { - // console.log("DTO : \n") - // console.log({...createFriendshipDto}) - const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername}); if (!receiver) throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND); if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED) throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND); - const friendship = await this.friendshipRepository .createQueryBuilder('friendship') @@ -218,21 +185,13 @@ export class FriendshipService { .andWhere('receiver.id = :receiverId2', {receiverId2: creator.id}) .getOne(); - // console.log('friendship.service create, friendship: \n\n\n') - // console.log({...friendship}) - if (friendship) { - // console.log('there is already a friend request') - if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED) throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK); else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED) { if (friendship && friendship.sender && friendship.sender.id === creator.id) { 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); @@ -242,7 +201,6 @@ export class FriendshipService { else if (friendship.status && friendship.status === FriendshipStatus.DECLINED) throw new HttpException(`The request has been declined.`, HttpStatus.OK); } - // console.log('friendship.service create, we are still saving a new friendship') const newFriendship = new Friendship(); newFriendship.sender = creator; @@ -259,10 +217,6 @@ export class FriendshipService { .leftJoinAndSelect('friendship.receiver', 'receiver') .where('friendship.id = :friendshipId', { friendshipId: relationshipId }) .getOne(); - - // console.log('.service accept friendship') - // console.log({...relation}) - if (!relation) throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND); if (relation.sender.id === user.id) { @@ -304,8 +258,6 @@ export class FriendshipService { // in the case where you RECEIVED the friendship but now want to block that person if (relation.receiver && relation.receiver.id === user.id) { - // console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block') - // console.log({...relation}) const newFriendshipDto = {"receiverUsername": relation.sender.username, "status": FriendshipStatus.BLOCKED}; await this.removeFriendship(relationshipId, user); return await this.create(newFriendshipDto, user); @@ -328,17 +280,10 @@ export class FriendshipService { if (friendship.sender.id !== user.id && friendship.receiver.id !== user.id) { throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN); } - - // console.log('.service deleted a friendship') - return this.friendshipRepository.remove(friendship); } async findIfUserIsBlockedOrHasBlocked(userConnectedId: number, userToFindId: number) { - // console.log("finding if user is blocked") - // console.log('user connected: ' + userConnectedId) - // console.log('user to find: ' + userToFindId) - const friendship = await this.friendshipRepository .createQueryBuilder('friendship') .leftJoinAndSelect('friendship.sender', 'sender') @@ -362,17 +307,11 @@ export class FriendshipService { .andWhere('friendship.status = :status', {status : FriendshipStatus.BLOCKED}) .getOne() - - // console.log('printing friendship queried') - // console.log({...friendship}) - if (friendship) { console.log('we are blocked in friendship.service') return true; } - - // console.log('we are not blocked in friendship service') - return false; } + } diff --git a/srcs/requirements/nestjs/api_back/src/friendship/sendableFriendship.ts b/srcs/requirements/nestjs/api_back/src/friendship/sendableFriendship.ts index 64e0736c..0b984a8a 100644 --- a/srcs/requirements/nestjs/api_back/src/friendship/sendableFriendship.ts +++ b/srcs/requirements/nestjs/api_back/src/friendship/sendableFriendship.ts @@ -1,11 +1,6 @@ import { Friendship, FriendshipStatus } from "./entities/friendship.entity"; - -// Ok i don't really know what i'm doing but i want a thing that is typeset that i can use to send info back to the Front when they create a friendship or ask for a friendship -// Ok it doesn't seem like i really need an interface, that just enfoces the types - -// export interface SendableFriendship { export class SendableFriendship { id: number; date: Date; @@ -13,7 +8,6 @@ export class SendableFriendship { receiverUsername: string; status: FriendshipStatus; - // if my constructor is here won't it get sent all over the place too? constructor(friendship: Friendship) { this.id = friendship.id; this.date = friendship.date diff --git a/srcs/requirements/nestjs/api_back/src/users/sendableUsers.ts b/srcs/requirements/nestjs/api_back/src/users/sendableUsers.ts index fca212bb..90f94198 100644 --- a/srcs/requirements/nestjs/api_back/src/users/sendableUsers.ts +++ b/srcs/requirements/nestjs/api_back/src/users/sendableUsers.ts @@ -8,7 +8,6 @@ export class SendableUser { status: string; stats: UserStats; - // if my constructor is here won't it get sent all over the place too? constructor(user: User) { this.username = user.username; this.image_url = user.image_url; diff --git a/srcs/requirements/nestjs/api_back/src/users/users.service.ts b/srcs/requirements/nestjs/api_back/src/users/users.service.ts index 680075da..dd8fcd6b 100644 --- a/srcs/requirements/nestjs/api_back/src/users/users.service.ts +++ b/srcs/requirements/nestjs/api_back/src/users/users.service.ts @@ -4,11 +4,9 @@ import { User } from './entities/user.entity'; import { Repository, Not } from 'typeorm'; import { CreateUsersDto } from './dto/create-users.dto'; import { UpdateUsersDto } from './dto/update-users.dto'; -import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto'; import { UserStats } from './entities/userStat.entities'; import { FriendshipService } from 'src/friendship/friendship.service'; -// On va devoir sûrement trouver un moyen plus simple pour passer l'id, sûrement via des pipes -// ou des interceptors, mais pour l'instant on va faire comme ça. + @Injectable() export class UsersService { @@ -22,16 +20,12 @@ export class UsersService { const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id}); if (!user) { - // console.log(`The requested user not found.`); return null; } - // console.log(`The requested user found.`); return user; } async findOne(username: string) { - // console.log(`FIND ONE USER SERVICE Find user ${username}`); - const user = await this.userRepository.createQueryBuilder('user') .leftJoinAndSelect('user.stats', 'stats') .where('user.username = :username', { username: username }) @@ -39,8 +33,6 @@ export class UsersService { if (!user) 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); - const partialUser : Partial = { username: user.username, image_url: user.image_url, @@ -48,9 +40,6 @@ export class UsersService { status: user.status, stats: user.stats, }; - - // console.log(`Returned Partial User.` + partialUser.username + user.username); - return partialUser; } @@ -69,26 +58,14 @@ export class UsersService { let partialUsers : Partial[] = []; for (const otherUser of otherUsers) { - // console.log('other user: ') - // console.log({...otherUser}) - // let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id); - // console.log('user.services findIF Blocked... : ') - // console.log(tmp) - // if (tmp === false) { if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) { 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}) - return partialUsers; } async create(createUserDto: CreateUsersDto) { - // console.log('\nuser.services create a new user, createUserDto: ') - // console.log({...createUserDto}) if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId})) throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT); const user = this.userRepository.create(createUserDto); @@ -101,7 +78,6 @@ export class UsersService { async update(id: number, updateUserDto: UpdateUsersDto, username : string) { console.log("Maj user username : " + username + " updateuser dto " + updateUserDto.username ) if (await this.isUsernameExists(updateUserDto.username) === true && updateUserDto.username !== username) { - // console.log('updating username ' + updateUserDto.username + ' but it already is in use') throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT); } const user = await this.userRepository.preload( @@ -143,15 +119,12 @@ export class UsersService { return this.userRepository.update(id, {image_url: avatar}); } - // 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(username: string) { const user = await this.userRepository.findOneBy({username: username}); if (!user) throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND); - // console.log('user.service getAvatarUrl of ' + user.username) if (!user.image_url) throw new HttpException(`The user has no avatar.`,HttpStatus.NOT_FOUND); - // console.log('User.service Avatar URL ' + user.image_url); return user.image_url; } diff --git a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte index 428f589c..90ffadb0 100644 --- a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte @@ -1,5 +1,4 @@ -

2FA Sign In

use google authenticator

{#await fetchQrCodeImg}

Please Wait...

{:then data} - A QRCodeImg you must scan with google authenticator
{#if wrongCode} -
{wrongCode}
@@ -83,18 +79,13 @@ \ No newline at end of file diff --git a/srcs/requirements/svelte/api_front/src/pieces/GenerateUserDisplay.svelte b/srcs/requirements/svelte/api_front/src/pieces/GenerateUserDisplay.svelte index 058a4f70..198d19f0 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/GenerateUserDisplay.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/GenerateUserDisplay.svelte @@ -3,7 +3,6 @@ export let user; let rank = ''; - let avatar; if (user.stats.loseGame > user.stats.winGame) { rank = "Come on, you can do better" @@ -47,13 +46,11 @@
{#if user}
- {#await fetchAvatar(user.username) then avatar} user avatar {:catch error}

Avatar was unable to load

{/await} -
{user.username}
Rank: @@ -102,11 +99,8 @@ text-align: center; } -/* Normal CSS stuff */ .avatar{ max-width: 150px; - /* width: 1em; */ - /* padding: 5px; */ } /* The variable rich section */ @@ -114,10 +108,8 @@ max-width: 600px; margin: 40px auto; text-align: center; - /* i think i want to use a grid? */ display: grid; grid-template-columns: repeat(3, 1fr); - /* not sure about this, maybe top should be larger? */ grid-template-rows: repeat(3, 1fr); } @@ -139,12 +131,6 @@ font-weight: bold; } - .error{ - font-size: 1vw; - font-weight: bold; - color: red; - } - .errorA{ font-size: 0.5em; font-weight: bold; @@ -173,8 +159,6 @@ } - - /* Glittery Star Stuff */ diff --git a/srcs/requirements/svelte/api_front/src/pieces/Header.svelte b/srcs/requirements/svelte/api_front/src/pieces/Header.svelte index 59b67f75..66fef6e1 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/Header.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/Header.svelte @@ -2,11 +2,6 @@ import { push } from "svelte-spa-router"; import { location } from 'svelte-spa-router'; - - // no need, it's just for links - import active from 'svelte-spa-router/active' - // or i could leave them all and not display if they're active? - $: current = $location; let handleClickLogout = async () => diff --git a/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte b/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte index 384cc84e..3f749189 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte +++ b/srcs/requirements/svelte/api_front/src/pieces/Tabs.svelte @@ -24,7 +24,6 @@ .tab.big{ margin-bottom: 50px; - /* guessing at size */ } .tab.medium{ margin-bottom: 40px; @@ -32,7 +31,6 @@ } .tab.small{ margin-bottom: 10px; - /* need it small */ } ul{ display: flex; @@ -41,15 +39,12 @@ list-style-type: none; } li{ - /* margin: 0 16px; */ - /* font-size: 18px; */ color: #555; cursor: pointer; } li.big{ margin: 0 20px; font-size: 22px; - /* guessing at size */ } li.medium{ margin: 0 16px; @@ -59,7 +54,6 @@ li.small{ margin: 8px; font-size: 10px; - /* need it small */ } .active{ @@ -79,7 +73,6 @@ li.default{ margin: 0 16px; font-size: 18px; - /* the OG size */ } @media screen and (max-width: 700px) { @@ -93,5 +86,4 @@ } } - \ No newline at end of file diff --git a/srcs/requirements/svelte/api_front/src/pieces/utils.ts b/srcs/requirements/svelte/api_front/src/pieces/utils.ts index 225b8dd1..91295b28 100644 --- a/srcs/requirements/svelte/api_front/src/pieces/utils.ts +++ b/srcs/requirements/svelte/api_front/src/pieces/utils.ts @@ -6,7 +6,6 @@ export async function fetchAvatar(username?: string) url += `?username=${username}`; } - // throw new Error("HTTP ") return fetch(url) .then((response) => { if (!response.ok) { diff --git a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js index 87af3079..9bd7b912 100644 --- a/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/primaryRoutes.js @@ -12,11 +12,9 @@ import { fetchUser } from "../pieces/utils"; async function checkLogin(detail) { const user = await fetchUser(); if (!user || !user.username) { - // console.log('failed to be logged in') return false; } else { - // console.log('successfully logged in') return true; } } diff --git a/srcs/requirements/svelte/api_front/src/routes/profileRoutes.js b/srcs/requirements/svelte/api_front/src/routes/profileRoutes.js index dd0dfb19..510548ed 100644 --- a/srcs/requirements/svelte/api_front/src/routes/profileRoutes.js +++ b/srcs/requirements/svelte/api_front/src/routes/profileRoutes.js @@ -5,8 +5,6 @@ import ProfileSettings from '../pages/profile/ProfileSettings.svelte'; import ProfileUsers from '../pages/profile/ProfileUsers.svelte'; 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 export const prefix = '/profile'; @@ -15,6 +13,5 @@ export const profileRoutes = { '/settings': ProfileSettings, '/users': ProfileUsers, '/users/:username': ProfileDisplayOneUser, - // '/users/:username': DisplayAUser, '*': NotFound };