Browse Source

channel-message foreign key error fix that i probably broke

master
Pheuw1 2 years ago
parent
commit
f89e1a6509
  1. 18
      back/volume/src/chat/chat.gateway.ts
  2. 4
      back/volume/src/chat/chat.service.ts
  3. 2
      back/volume/src/chat/entity/message.entity.ts
  4. 1
      front/volume/src/components/Chat.svelte

18
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<void> {
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

4
back/volume/src/chat/chat.service.ts

@ -163,8 +163,8 @@ export class ChatService {
await this.ChannelRepository.save(channel)
}
async removeChannel (channelId: number): Promise<void> {
await this.ChannelRepository.delete(channelId)
async removeChannel(channelId: number): Promise<void> {
await this.ChannelRepository.remove(await this.getFullChannel(channelId))
}
async isOwner (id: number, userId: number): Promise<boolean> {

2
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

1
front/volume/src/components/Chat.svelte

@ -420,6 +420,7 @@
padding: 1rem;
max-width: 90%;
width: auto;
margin: auto;
display: flex;
flex-direction: column;
}

Loading…
Cancel
Save