diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index c3c08d2..248253d 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -67,12 +67,12 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { channel, user ) - const conUser = { - user: user.id, - channel: channel.id, - socket: socket.id - } - this.connectedUserRepository.create(conUser) + const conUser = new ConnectedUser() + conUser.user = user.id + conUser.channel = channel.id + conUser.socket = socket.id + const test = await this.connectedUserRepository.save(conUser) + console.log(test) this.server.to(socket.id).emit('messages', messages) await socket.join(channel.id.toString()) console.log(this.server.sockets.adapter.rooms.get(channel.id.toString())) @@ -94,7 +94,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { const connect = await this.connectedUserRepository.findOneBy({ socket: socket.id }) - console.log("connection removed", connect?.user) + console.log('connection removed', connect?.user) if (connect == null) return const channel = await this.chatService.getFullChannel(connect.channel) socket.disconnect() @@ -124,7 +124,9 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { @SubscribeMessage('kickUser') async onKickUser (socket: Socket, kick: kickUserDto): Promise { const channel = await this.chatService.getFullChannel(kick.chan) - if (channel.owner.id === kick.to) { throw new WsException('You cannot kick the owner of a channel') } + if (channel.owner.id === kick.to) { + throw new WsException('You cannot kick the owner of a channel') + } if ( channel.owner.id !== kick.from && channel.admins.findIndex((usr) => usr.id === kick.from) === -1 diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index f5d28c2..9603727 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -163,8 +163,8 @@ export class ChatService { await this.ChannelRepository.save(channel) } - async removeChannel (channelId: number): Promise { - await this.ChannelRepository.delete(channelId) + async removeChannel(channelId: number): Promise { + await this.ChannelRepository.remove(await this.getFullChannel(channelId)) } async isOwner (id: number, userId: number): Promise { diff --git a/back/volume/src/chat/entity/message.entity.ts b/back/volume/src/chat/entity/message.entity.ts index 24d3012..e87e315 100644 --- a/back/volume/src/chat/entity/message.entity.ts +++ b/back/volume/src/chat/entity/message.entity.ts @@ -22,7 +22,7 @@ export default class Message { @JoinColumn() author: User - @ManyToOne(() => Channel, (channel) => channel.messages) + @ManyToOne(() => Channel, (channel) => channel.messages, { onDelete: 'CASCADE' }) @JoinTable() channel: Channel diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 9e129e4..a0c9d99 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -420,6 +420,7 @@ padding: 1rem; max-width: 90%; width: auto; + margin: auto; display: flex; flex-direction: column; }