Skip to content

Commit

Permalink
Merge pull request #29 from regenbogen-ice/canary
Browse files Browse the repository at this point in the history
fix: sql misspelling in train_trips fetch from train_vehicle
  • Loading branch information
AdriDevelopsThings authored Nov 20, 2024
2 parents 2e6f6fd + e4c6c7e commit cc1880b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/graphql/resolvers/train_vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cc1880b

Please sign in to comment.