32 lines
956 B
TypeScript
32 lines
956 B
TypeScript
import { BaseEvent } from '@/application/base/baseEvent'
|
|
import { SocketEvent } from '@/application/enums'
|
|
import type { UUID } from '@/application/types'
|
|
import ItemRepository from '@/repositories/itemRepository'
|
|
|
|
interface IPayload {
|
|
id: UUID
|
|
}
|
|
|
|
export default class ItemDeleteEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on(SocketEvent.GM_ITEM_REMOVE, this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
const itemRepository = new ItemRepository()
|
|
const item = await itemRepository.getById(data.id)
|
|
if (!item) return callback(false)
|
|
|
|
await item.delete()
|
|
|
|
return callback(true)
|
|
} catch (error) {
|
|
this.logger.error(`Error deleting item ${data.id}: ${error instanceof Error ? error.message : String(error)}`)
|
|
return callback(false)
|
|
}
|
|
}
|
|
}
|