fix: improve plugins functionality with server management

This commit is contained in:
2026-04-29 20:33:54 +02:00
parent b8f6d58d99
commit fa2cca6fa4
82 changed files with 1708 additions and 303 deletions

View File

@@ -1,11 +1,28 @@
import { DataSource } from 'typeorm';
import { RoomEntity } from '../../../entities';
import { RoomEntity, RoomOwnerEntity } from '../../../entities';
import { rowToRoom } from '../../mappers';
import { loadRoomRelationsMap } from '../../relations';
import { getCurrentUserScope } from '../../current-user-scope';
export async function handleGetAllRooms(dataSource: DataSource) {
const currentUserId = await getCurrentUserScope(dataSource);
if (!currentUserId) {
return [];
}
const repo = dataSource.getRepository(RoomEntity);
const rows = await repo.find();
const ownershipRows = await dataSource.getRepository(RoomOwnerEntity).find({ where: { userId: currentUserId } });
const roomIds = ownershipRows.map((owner) => owner.roomId);
if (roomIds.length === 0) {
return [];
}
const rows = await repo
.createQueryBuilder('room')
.where('room.id IN (:...roomIds)', { roomIds })
.getMany();
const relationsByRoomId = await loadRoomRelationsMap(dataSource, rows.map((row) => row.id));
return rows.map((row) => rowToRoom(row, relationsByRoomId.get(row.id)));