import Chat from "../../../entities/Chat" ; import User from "../../../entities/User" ; import { GetChatQueryArgs , GetChatResponse } from "../../../types/graph" ; import { Resolvers } from "../../../types/resolvers" ; import privateResolver from "../../../utils/privateResolver" ; const resolvers = { Query : { GetChat : privateResolver ( async ( _ , args , { req } ) : Promise < GetChatResponse > => { const user = req . user ; try { const chat = await Chat . findOne ( { id : args . chatId } , { relations : [ "messages" ] } ) ; if ( chat ) { if ( chat . passengerId === user . id || chat . driverId === user . id ) { return { ok : true , error : null , chat } ; } else { return { ok : false , error : "Not authorized to see this chat" , chat : null } ; } } else { return { ok : false , error : "Not found" , chat : null } ; } } catch ( error ) { return { ok : false , error : error . message , chat : null } ; } } ) } } ; export default resolvers ;