import Ride from "../../../entities/Ride" ; import User from "../../../entities/User" ; import { GetRideQueryArgs , GetRideResponse } from "../../../types/graph" ; import { Resolvers } from "../../../types/resolvers" ; import privateResolver from "../../../utils/privateResolver" ; const resolvers = { Query : { GetRide : privateResolver ( async ( _ , args , { req } ) : Promise < GetRideResponse > => { const user = req . user ; try { const ride = await Ride . findOne ( { id : args . rideId } ) ; if ( ride ) { if ( ride . passengerId === user . id || ride . driverId === user . id ) { return { ok : true , error : null , ride } ; } else { return { ok : false , error : "Not Authorized" , ride : null } ; } } else { return { ok : false , error : "Ride not found" , ride : null } ; } } catch ( error ) { return { ok : false , error : error . message , ride : null } ; } } ) } } ; export default resolvers ;