30 lines
836 B
TypeScript
30 lines
836 B
TypeScript
import { BaseEvent } from '#application/base/baseEvent'
|
|
import { UUID } from '#application/types'
|
|
import MapRepository from '#repositories/mapRepository'
|
|
|
|
type Payload = {
|
|
mapId: UUID
|
|
}
|
|
|
|
export default class MapDeleteEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('gm:map:delete', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
try {
|
|
this.logger.info(`Deleting map ${data.mapId}`)
|
|
|
|
await (await MapRepository.getById(data.mapId))?.delete()
|
|
|
|
this.logger.info(`Map ${data.mapId} deleted successfully.`)
|
|
return callback(true)
|
|
} catch (error: unknown) {
|
|
this.logger.error('gm:map:delete error', error)
|
|
return callback(false)
|
|
}
|
|
}
|
|
}
|