26 lines
727 B
TypeScript
26 lines
727 B
TypeScript
import { BaseEvent } from '#application/base/baseEvent'
|
|
import { Item } from '#entities/item'
|
|
import ItemRepository from '#repositories/itemRepository'
|
|
|
|
interface IPayload {}
|
|
|
|
export default class ItemListEvent extends BaseEvent {
|
|
public listen(): void {
|
|
this.socket.on('gm:item:list', this.handleEvent.bind(this))
|
|
}
|
|
|
|
private async handleEvent(data: IPayload, callback: (response: Item[]) => void): Promise<void> {
|
|
try {
|
|
if (!(await this.isCharacterGM())) return
|
|
|
|
const itemRepository = new ItemRepository()
|
|
const items = await itemRepository.getAll()
|
|
|
|
return callback(items)
|
|
} catch (error) {
|
|
this.logger.error('gm:item:list error', error)
|
|
return callback([])
|
|
}
|
|
}
|
|
}
|