From f7d3c2e45c4e08189bea89a0914974c2dae14b0c Mon Sep 17 00:00:00 2001 From: vvandenb Date: Thu, 23 Mar 2023 16:36:32 +0100 Subject: [PATCH] * Various fixes --- back/src/chat/chat.controller.ts | 7 +++---- back/src/chat/chat.gateway.ts | 6 +++--- back/src/chat/dto/updateUser.dto.ts | 9 +++++++-- front/src/components/Alert/Alert.svelte | 1 - front/src/components/Channels.svelte | 2 +- front/src/components/Chat.svelte | 11 +++++++++-- front/src/components/Friends.svelte | 17 ----------------- front/src/components/Pong/Pong.svelte | 2 +- front/src/components/Profile.svelte | 13 +++++-------- 9 files changed, 29 insertions(+), 39 deletions(-) diff --git a/back/src/chat/chat.controller.ts b/back/src/chat/chat.controller.ts index e6fcb13..dbbe2ab 100644 --- a/back/src/chat/chat.controller.ts +++ b/back/src/chat/chat.controller.ts @@ -18,10 +18,9 @@ import { CreateChannelDto } from './dto/create-channel.dto' import { IdDto, PasswordDto, MuteDto } from './dto/updateUser.dto' import type User from 'src/users/entity/user.entity' -import Channel from './entity/channel.entity' +import type Channel from './entity/channel.entity' import { Profile42 } from 'src/auth/42.decorator' import { Profile } from 'passport-42' -import { IsNumberString, IsPositive } from 'class-validator' @Controller('channels') @UseGuards(AuthenticatedGuard) @@ -145,7 +144,7 @@ export class ChatController { const channel = await this.channelService.getFullChannel(id) const user: User | null = await this.usersService.findUser(+target.data[0]) if (isNaN(+target.data[1])) { - throw new BadRequestException(`Invalid duration ${+target.data[1]}`) + throw new BadRequestException('Invalid duration') } if (user == null) { throw new NotFoundException(`User #${+target.data[0]} not found`) @@ -174,7 +173,7 @@ export class ChatController { const channel = await this.channelService.getFullChannel(id) const user: User | null = await this.usersService.findUser(+mute.data[0]) if (isNaN(+mute.data[1])) { - throw new BadRequestException(`Invalid duration ${+mute.data[1]}`) + throw new BadRequestException('Invalid duration') } if (user == null) { throw new NotFoundException(`User #${+mute.data[0]} not found`) diff --git a/back/src/chat/chat.gateway.ts b/back/src/chat/chat.gateway.ts index 8744fd4..e80bd5c 100644 --- a/back/src/chat/chat.gateway.ts +++ b/back/src/chat/chat.gateway.ts @@ -98,7 +98,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { if (connect == null) return false; const channel = await this.chatService.getFullChannel(connect.channel); if (connect.user === channel.owner.ftId) { - this.server.in(channel.id.toString()).emit('kicked'); + this.server.in(channel.id.toString()).emit('deleted'); await this.chatService.removeChannel(channel.id); } else { channel.users = channel.users.filter((usr: User) => usr.ftId !== connect.user); @@ -114,8 +114,8 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { let channel: Channel | null = null channel = await this.chatService.getChannel(message.ChannelId).catch(() => { return null }) if (channel == null) { - this.server.to(socket.id).emit('kicked') - throw new WsException('Channel has been removed by owner'); + this.server.to(socket.id).emit('deleted') + throw new WsException('Channel has been deleted'); } if (await this.chatService.isMuted(channel.id, message.UserId)) { throw new WsException('You are muted'); diff --git a/back/src/chat/dto/updateUser.dto.ts b/back/src/chat/dto/updateUser.dto.ts index ca11d95..d13d70c 100644 --- a/back/src/chat/dto/updateUser.dto.ts +++ b/back/src/chat/dto/updateUser.dto.ts @@ -1,4 +1,5 @@ -import { IsEmail, IsNumber, IsString } from 'class-validator' +import { Type } from 'class-transformer' +import { IsArray, IsEmail, IsNumber, IsPositive, IsString } from 'class-validator' export class IdDto { @IsNumber() @@ -11,7 +12,11 @@ export class PasswordDto { } export class MuteDto { - data: number[] + @Type(() => Number) + @IsArray() + @IsNumber({}, { each: true }) + @IsPositive({ each: true }) + data: number[] } export class EmailDto { diff --git a/front/src/components/Alert/Alert.svelte b/front/src/components/Alert/Alert.svelte index 68d6272..0cd6189 100644 --- a/front/src/components/Alert/Alert.svelte +++ b/front/src/components/Alert/Alert.svelte @@ -1,6 +1,5 @@
-
  • - dispatch("view-profile", $store.username)} - on:keydown={() => dispatch("view-profile", $store.username)} - style="cursor: pointer;" - >{$store.username} is {$store.status} -
  • {$store.username} friends:

    {#if friends.length > 0}
    diff --git a/front/src/components/Pong/Pong.svelte b/front/src/components/Pong/Pong.svelte index 59d91a4..0cc87ee 100644 --- a/front/src/components/Pong/Pong.svelte +++ b/front/src/components/Pong/Pong.svelte @@ -101,7 +101,7 @@ gamePlaying = true; } else { gamePlaying = false; - popup.set(bind(Alert, { message: "Failed to invite user. Is he currently connected to the game?", form: false })) + show_popup("Failed to invite user. Is he currently connected to the game?", false) } }); socket.on(GAME_EVENTS.MATCHMAKING, (data: MatchmakingDto) => { diff --git a/front/src/components/Profile.svelte b/front/src/components/Profile.svelte index 9e207f4..2b2b033 100644 --- a/front/src/components/Profile.svelte +++ b/front/src/components/Profile.svelte @@ -100,7 +100,7 @@ async function handleSubmit() { if (gamePlaying) { - popup.set(bind(Alert, { message: "Cannot change username while playing.", form: false })) + await show_popup("Cannot change username while playing.", false) return; } @@ -125,11 +125,11 @@ if (response.ok) { $store.username = username; $store.email = email; - popup.set(bind(Alert, { message: "Succefully changed informations.", form: false })) + await show_popup("Succefully changed informations.", false) resetGameConnection(); } else { const error = await response.json(); - popup.set(bind(Alert, { message: error.message, form: false})) + await show_popup(error.message, false) } } @@ -143,17 +143,14 @@ credentials: "include", }); if (response.ok) { - popup.set(bind(Alert, { - message: "Succefully " + (user.twoFA ? "enabled" : "disabled") + " 2FA", - form : false - })) + await show_popup("Succefully " + (user.twoFA ? "enabled" : "disabled") + " 2FA", false) } }
    -

    ===| {username}'s Profile |===

    +

    ===| {username} |===

    {#if !edit} avatar