import { DataSource } from 'typeorm'; import { RoomEntity } from '../../../entities'; import { SaveRoomCommand } from '../../types'; export async function handleSaveRoom(command: SaveRoomCommand, dataSource: DataSource): Promise { const repo = dataSource.getRepository(RoomEntity); const { room } = command.payload; const entity = repo.create({ id: room.id, name: room.name, description: room.description ?? null, topic: room.topic ?? null, hostId: room.hostId, password: room.password ?? null, hasPassword: room.hasPassword ? 1 : 0, isPrivate: room.isPrivate ? 1 : 0, createdAt: room.createdAt, userCount: room.userCount ?? 0, maxUsers: room.maxUsers ?? null, icon: room.icon ?? null, iconUpdatedAt: room.iconUpdatedAt ?? null, permissions: room.permissions != null ? JSON.stringify(room.permissions) : null, channels: room.channels != null ? JSON.stringify(room.channels) : null, members: room.members != null ? JSON.stringify(room.members) : null, sourceId: room.sourceId ?? null, sourceName: room.sourceName ?? null, sourceUrl: room.sourceUrl ?? null }); await repo.save(entity); }