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:
2025-09-30 15:23:50 -07:00
parent c244a4b037
commit 415b461308
12 changed files with 262 additions and 19 deletions

View File

@@ -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;