server/src/app/events/gm/object/GmObjectDetails.ts
2024-07-04 13:38:12 +02:00

33 lines
808 B
TypeScript

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);
}
});
}