mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Add sorting to all data types
- Add name-based sorting for entities with names - Add order-based sorting for ordered stops - Add "seconds remaining" based sorting for ETAs - Add tests to check sorting
This commit is contained in:
@@ -3,7 +3,7 @@ import { ServerContext } from "../ServerContext";
|
||||
|
||||
export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
Shuttle: {
|
||||
eta: async (parent, args, contextValue, info) => {
|
||||
eta: async (parent, args, contextValue, _) => {
|
||||
if (!args.forStopId) return null;
|
||||
|
||||
const system = contextValue.findSystemById(parent.systemId);
|
||||
@@ -21,7 +21,7 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
updatedTimeMs: etaForStopId.updatedTime,
|
||||
};
|
||||
},
|
||||
etas: async (parent, args, contextValue, info) => {
|
||||
etas: async (parent, args, contextValue, _) => {
|
||||
const system = contextValue.findSystemById(parent.systemId);
|
||||
if (!system) return null;
|
||||
|
||||
@@ -45,12 +45,14 @@ export const ShuttleResolvers: Resolvers<ServerContext> = {
|
||||
}));
|
||||
|
||||
if (computedEtas.every((eta) => eta !== null)) {
|
||||
return computedEtas;
|
||||
return computedEtas
|
||||
.slice()
|
||||
.sort((a, b) => (a!.secondsRemaining - b!.secondsRemaining));
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
route: async (parent, args, contextValue, info) => {
|
||||
route: async (parent, args, contextValue, _) => {
|
||||
const system = contextValue.findSystemById(parent.systemId);
|
||||
if (!system) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user