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 @@