45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { Server } from 'socket.io'
|
|
import { TSocket } from '../../../../utilities/types'
|
|
import prisma from '../../../../utilities/prisma'
|
|
import CharacterManager from '../../../../managers/characterManager'
|
|
import characterRepository from '../../../../repositories/characterRepository'
|
|
|
|
type Payload = {
|
|
id: string
|
|
name: string
|
|
tags: string[]
|
|
}
|
|
|
|
/**
|
|
* Handle game master tile update event
|
|
* @param socket
|
|
* @param io
|
|
*/
|
|
export default function (socket: TSocket, io: Server) {
|
|
socket.on('gm:tile:update', async (data: Payload, callback: (success: boolean) => void) => {
|
|
const character = await characterRepository.getById(socket.characterId as number);
|
|
if (!character) return callback(false)
|
|
|
|
if (character.role !== 'gm') {
|
|
return
|
|
}
|
|
|
|
try {
|
|
const Tile = await prisma.tile.update({
|
|
where: {
|
|
id: data.id
|
|
},
|
|
data: {
|
|
name: data.name,
|
|
tags: data.tags
|
|
}
|
|
})
|
|
|
|
callback(true)
|
|
} catch (error) {
|
|
console.error(error)
|
|
callback(false)
|
|
}
|
|
})
|
|
}
|