import { BaseRepository } from '#application/base/baseRepository' import { UUID } from '#application/types' import { Map } from '#entities/map' import { MapEventTile } from '#entities/mapEventTile' class MapRepository extends BaseRepository { public readonly POPULATE_ALL = ['*'] public readonly POPULATE_MAP_EDITOR = ['mapEventTiles', 'placedMapObjects', 'mapEffects'] public readonly POPULATE_TELEPORT = ['placedMapObjects', 'mapEffects'] async getFirst(): Promise { try { const repository = this.getEntityManager().getRepository(Map) const result = await repository.findOne({ id: { $exists: true } }) if (result) result.setEntityManager(this.getEntityManager()) return result } catch (error: any) { this.logger.error(`Failed to get first map: ${error instanceof Error ? error.message : String(error)}`) return null } } async getAll(): Promise { try { const repository = this.getEntityManager().getRepository(Map) const results = await repository.findAll() for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get all map: ${error.message}`) return [] } } async getById(id: UUID) { try { const repository = this.getEntityManager().getRepository(Map) const result = await repository.findOne({ id }) if (result) result.setEntityManager(this.getEntityManager()) return result } catch (error: any) { this.logger.error(`Failed to get map by id: ${error.message}`) return null } } async getEventTiles(id: UUID): Promise { try { const repository = this.getEntityManager().getRepository(MapEventTile) const results = await repository.find({ map: id }) for (const result of results) result.setEntityManager(this.getEntityManager()) return results } catch (error: any) { this.logger.error(`Failed to get map event tiles: ${error.message}`) return [] } } async getFirstEventTile(mapId: UUID, positionX: number, positionY: number): Promise { try { const repository = this.getEntityManager().getRepository(MapEventTile) const result = await repository.findOne({ map: mapId, positionX: positionX, positionY: positionY }) if (result) result.setEntityManager(this.getEntityManager()) return result } catch (error: any) { this.logger.error(`Failed to get map event tile: ${error.message}`) return null } } } export default MapRepository