29 lines
899 B
JavaScript
29 lines
899 B
JavaScript
require('dotenv').config();
|
|
|
|
const db = require('./db');
|
|
|
|
/**
|
|
* Get trips that belong to the certain route_id and day
|
|
*
|
|
* @return Array of trips
|
|
*/
|
|
async function get(routeid = 0, day = '2023-12-16') {
|
|
|
|
const schema = process.env.DB_SCHEMA || 'schema';
|
|
|
|
const tomorrow = new Date(day);
|
|
tomorrow.setUTCDate(tomorrow.getUTCDate() + 1);
|
|
|
|
const query = `SELECT agency_name, agency_id, route_id, route_short_name, service_id, trip_id, trip_short_name, trip_headsign, timestamp_pgsql FROM `
|
|
+ schema
|
|
+ `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND route_id = '${routeid}' AND ((timestamp_pgsql >= '${day}' AND timestamp_pgsql < '`
|
|
+ tomorrow.toISOString().substring(0, 10)
|
|
+ `') OR timestamp_pgsql IS NULL) ORDER BY agency_name ASC, route_short_name ASC, trip_short_name ASC;`
|
|
|
|
return await db.query(query);
|
|
};
|
|
|
|
module.exports = {
|
|
get
|
|
};
|