1
0
forked from noxious/server

Renamed folder

This commit is contained in:
2024-12-28 22:12:59 +01:00
parent 0bc81ba4cc
commit e1ff2fefe1
49 changed files with 2 additions and 2 deletions

View File

@ -0,0 +1,56 @@
import { ItemType, ItemRarity } from '@prisma/client'
import { Server } from 'socket.io'
import { gameMasterLogger } from '#application/logger'
import prisma from '#application/prisma'
import { TSocket } from '#application/types'
import characterRepository from '#repositories/characterRepository'
type Payload = {
id: string
name: string
description: string | null
itemType: ItemType
stackable: boolean
rarity: ItemRarity
spriteId: string | null
}
export default class ItemUpdateEvent {
constructor(
private readonly io: Server,
private readonly socket: TSocket
) {}
public listen(): void {
this.socket.on('gm:item:update', this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)
if (character.role !== 'gm') {
return callback(false)
}
try {
await prisma.item.update({
where: { id: data.id },
data: {
name: data.name,
description: data.description,
itemType: data.itemType,
stackable: data.stackable,
rarity: data.rarity,
spriteId: data.spriteId
}
})
return callback(true)
} catch (error) {
gameMasterLogger.error(`Error updating item: ${error instanceof Error ? error.message : String(error)}`)
return callback(false)
}
}
}