33 lines
923 B
TypeScript
33 lines
923 B
TypeScript
import type { UUID } from '#application/types'
|
|
|
|
import { BaseRepository } from '#application/base/baseRepository'
|
|
import { MapObject } from '#entities/mapObject'
|
|
|
|
class MapObjectRepository extends BaseRepository {
|
|
async getById(id: UUID): Promise<MapObject | null> {
|
|
try {
|
|
const repository = this.getEntityManager().getRepository(MapObject)
|
|
const result = await repository.findOne({ id })
|
|
if (result) result.setEntityManager(this.getEntityManager())
|
|
|
|
return result
|
|
} catch (error: any) {
|
|
return null
|
|
}
|
|
}
|
|
|
|
async getAll(): Promise<MapObject[]> {
|
|
try {
|
|
const repository = this.getEntityManager().getRepository(MapObject)
|
|
const results = await repository.findAll()
|
|
for (const result of results) result.setEntityManager(this.getEntityManager())
|
|
|
|
return results
|
|
} catch (error: any) {
|
|
return []
|
|
}
|
|
}
|
|
}
|
|
|
|
export default MapObjectRepository
|