import { Server } from "socket.io"; import {TSocket} from "../../../utilities/Types"; import ObjectRepository from '../../../repositories/ObjectRepository' import { Object } from '@prisma/client' interface IPayload { object: string; } // callback will return Object from Prisma type TCallback = (object: Object | null) => void; /** * Handle game master object details fetch event * @param socket * @param io */ export default function (socket: TSocket, io: Server) { socket.on('gm:object:details', async (data: IPayload, callback: TCallback) => { if (socket.character?.role !== 'gm') { return; } try { const object = await ObjectRepository.getById(data.object); callback(object); } catch (error) { console.error(error); callback(null); } }); }