import { DataSource } from 'typeorm'; import { MessageEntity } from '../../../entities'; import { SaveMessageCommand } from '../../types'; export async function handleSaveMessage(command: SaveMessageCommand, dataSource: DataSource): Promise { const repo = dataSource.getRepository(MessageEntity); const { message } = command.payload; const entity = repo.create({ id: message.id, roomId: message.roomId, channelId: message.channelId ?? null, senderId: message.senderId, senderName: message.senderName, content: message.content, timestamp: message.timestamp, editedAt: message.editedAt ?? null, reactions: JSON.stringify(message.reactions ?? []), isDeleted: message.isDeleted ? 1 : 0, replyToId: message.replyToId ?? null, }); await repo.save(entity); }