28 lines
899 B
TypeScript
28 lines
899 B
TypeScript
import { BaseEvent } from '#application/base/baseEvent'
|
|
import { UUID } from '#application/types'
|
|
import CharacterHairRepository from '#repositories/characterHairRepository'
|
|
|
|
interface IPayload {
|
|
id: UUID
|
|
}
|
|
|
|
export default class characterHairDeleteEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('gm:characterHair:remove', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
const characterHair = await CharacterHairRepository.getById(data.id)
|
|
await (await CharacterHairRepository.getById(data.id))?.delete()
|
|
|
|
return callback(true)
|
|
} catch (error) {
|
|
this.logger.error(`Error deleting character type ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
|
callback(false)
|
|
}
|
|
}
|
|
}
|