forked from noxious/server
Minor TS improvement
This commit is contained in:
parent
586bb0ca83
commit
6f84238503
@ -33,7 +33,7 @@ export class AssetsController extends BaseController {
|
||||
* @param res
|
||||
*/
|
||||
public async listTilesByZone(req: Request, res: Response) {
|
||||
const zoneId = parseInt(req.params.zoneId)
|
||||
const zoneId = req.params.zoneId as UUID
|
||||
|
||||
if (!zoneId || zoneId === 0) {
|
||||
return this.sendError(res, 'Invalid zone ID', 400)
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { FilterValue } from '@mikro-orm/core'
|
||||
|
||||
import { BaseRepository } from '#application/base/baseRepository'
|
||||
import { UUID } from '#application/types'
|
||||
import { unduplicateArray } from '#application/utilities'
|
||||
import { Tile } from '#entities/tile'
|
||||
import { Zone } from '#entities/zone'
|
||||
import ZoneService from '#services/zoneService'
|
||||
|
||||
class TileRepository extends BaseRepository {
|
||||
async getById(id: FilterValue<`${string}-${string}-${string}-${string}-${string}`>): Promise<any> {
|
||||
async getById(id: UUID) {
|
||||
try {
|
||||
const repository = this.em.getRepository(Tile)
|
||||
return await repository.findOne({ id })
|
||||
@ -16,33 +17,33 @@ class TileRepository extends BaseRepository {
|
||||
}
|
||||
}
|
||||
|
||||
async getByIds(ids: FilterValue<`${string}-${string}-${string}-${string}-${string}`>): Promise<any> {
|
||||
async getByIds(ids: UUID[]) {
|
||||
try {
|
||||
const repository = this.em.getRepository(Tile)
|
||||
return await repository.find({
|
||||
id: ids
|
||||
})
|
||||
} catch (error: any) {
|
||||
return null
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async getAll(): Promise<any> {
|
||||
async getAll() {
|
||||
try {
|
||||
const repository = this.em.getRepository(Tile)
|
||||
return await repository.findAll()
|
||||
} catch (error: any) {
|
||||
return null
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async getByZoneId(zoneId: number): Promise<any> {
|
||||
async getByZoneId(zoneId: UUID) {
|
||||
try {
|
||||
const repository = this.em.getRepository(Zone)
|
||||
const tileRepository = this.em.getRepository(Tile)
|
||||
|
||||
const zone = await repository.findOne({ id: zoneId })
|
||||
if (!zone) return null
|
||||
if (!zone) return []
|
||||
|
||||
const zoneTileArray = unduplicateArray(ZoneService.flattenZoneArray(JSON.parse(JSON.stringify(zone.tiles))))
|
||||
|
||||
@ -50,7 +51,7 @@ class TileRepository extends BaseRepository {
|
||||
id: zoneTileArray
|
||||
})
|
||||
} catch (error: any) {
|
||||
return null
|
||||
return []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user