mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
add etas resolver on shuttle object
This commit is contained in:
@@ -112,6 +112,34 @@ export const resolvers: Resolvers<ServerContext> = {
|
|||||||
|
|
||||||
return etaForNextStop;
|
return etaForNextStop;
|
||||||
},
|
},
|
||||||
|
etas: async (parent, args, contextValue, info) => {
|
||||||
|
const etasForShuttle = await contextValue.repository.getEtasForShuttleId(parent.id);
|
||||||
|
if (!etasForShuttle) return null;
|
||||||
|
|
||||||
|
const computedEtas = await Promise.all(etasForShuttle.map(async ({
|
||||||
|
secondsRemaining,
|
||||||
|
stopId,
|
||||||
|
}): Promise<Eta | null> => {
|
||||||
|
const stop = await contextValue.repository.getStopById(stopId);
|
||||||
|
if (stop === null) return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
secondsRemaining,
|
||||||
|
stop: {
|
||||||
|
coordinates: stop.coordinates,
|
||||||
|
id: stop.id,
|
||||||
|
name: stop.name,
|
||||||
|
},
|
||||||
|
shuttle: parent,
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (computedEtas.every((eta) => eta !== null)) {
|
||||||
|
return computedEtas;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Stop: {
|
Stop: {
|
||||||
orderedStops: async (parent, args, contextValue, info) => {
|
orderedStops: async (parent, args, contextValue, info) => {
|
||||||
@@ -140,11 +168,11 @@ export const resolvers: Resolvers<ServerContext> = {
|
|||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (!computedOrderedStops.every((value) => value !== null)) {
|
if (computedOrderedStops.every((value) => value !== null)) {
|
||||||
return [];
|
return computedOrderedStops as OrderedStop[];
|
||||||
}
|
}
|
||||||
|
|
||||||
return computedOrderedStops as OrderedStop[];
|
return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
OrderedStop: {
|
OrderedStop: {
|
||||||
@@ -192,5 +220,5 @@ export const resolvers: Resolvers<ServerContext> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user