34 lines
840 B
TypeScript
34 lines
840 B
TypeScript
import type { UUID } from '#application/types'
|
|
|
|
import { BaseEvent } from '#application/base/baseEvent'
|
|
import TileRepository from '#repositories/tileRepository'
|
|
|
|
type Payload = {
|
|
id: UUID
|
|
name: string
|
|
tags: string[]
|
|
}
|
|
|
|
export default class TileUpdateEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('gm:tile:update', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
const tileRepository = new TileRepository()
|
|
|
|
const tile = await tileRepository.getById(data.id)
|
|
if (!tile) return callback(false)
|
|
|
|
await tile.setName(data.name).setTags(data.tags).save()
|
|
|
|
return callback(true)
|
|
} catch (error) {
|
|
return callback(false)
|
|
}
|
|
}
|
|
}
|