From e4c6c7e3644a84d21a1cc1270b448c3032235d42 Mon Sep 17 00:00:00 2001 From: AdriDevelopsThings Date: Wed, 20 Nov 2024 21:18:30 +0100 Subject: [PATCH] fix: sql misspelling in train_trips fetch from train_vehicle --- src/graphql/resolvers/train_vehicle.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/graphql/resolvers/train_vehicle.ts b/src/graphql/resolvers/train_vehicle.ts index 0baa422..2230829 100644 --- a/src/graphql/resolvers/train_vehicle.ts +++ b/src/graphql/resolvers/train_vehicle.ts @@ -9,14 +9,17 @@ import limitParser from '../../limitParser.js' export const trainVehicleTripsQuery = async (parent: any, args: { limit?: number, ignore_finished_trips?: boolean, min_trips?: number }) => { const limit = limitParser('train_trips', args.limit) const min_trips = args.min_trips != null && args.min_trips != undefined && args.min_trips < limit ? args.min_trips : 1 - const queryTemplate = () => database('train_trip_vehicle').where({ train_vehicle_id: parent.id }) - .join('train_trip', 'train_trip_vehicle.train_trip_id', '=', 'train_trip.id') + const queryTemplate = () => database('train_trip_vehicle') + .join('train_trip', function() { + this.on('train_trip_vehicle.train_trip_id', '=', 'train_trip.id') + .andOn('train_trip_vehicle.train_vehicle_id', '=', parent.id) + }) .select(['train_trip_vehicle.group_index', 'train_trip_vehicle.origin', 'train_trip_vehicle.destination', 'train_trip_vehicle.timestamp', 'train_trip.train_type','train_trip.train_number', 'train_trip.origin_station', 'train_trip.destination_station', 'train_trip.initial_departure', 'train_trip.timestamp as train_trip_timestamp', 'train_trip.id', 'train_trip.routes_update_expire', 'train_trip.coach_sequence_update_expire']) .orderBy('train_trip.initial_departure', 'desc') let query = queryTemplate().limit(limit) if (args.ignore_finished_trips) { query = query.whereRaw('(SELECT MAX(arrival) FROM train_trip_route WHERE train_trip_id=train_trip.id) > ?', [toSQLTimestamp(DateTime.now().minus({ minutes: 5 }))]) - .whereRaw('(SELECT COUNT(id) FROM train_trip_route WHERE train_trip_id=train_trip_id) > 0') + .whereRaw('(SELECT COUNT(id) FROM train_trip_route WHERE train_trip_id=train_trip.id) > 0') } let trips = await query if (trips.length < min_trips && args.ignore_finished_trips) {