31 lines
944 B
JavaScript
31 lines
944 B
JavaScript
require('dotenv').config();
|
|
|
|
const db = require('./db');
|
|
|
|
/**
|
|
* Get trips that belong to the day
|
|
*
|
|
* @return Array of trips
|
|
*/
|
|
async function get(day = '2024-01-21') {
|
|
|
|
const schema = process.env.DB_SCHEMA || 'schema';
|
|
|
|
const tomorrow = new Date(day);
|
|
tomorrow.setUTCDate(tomorrow.getUTCDate() + 1);
|
|
|
|
const query = `SELECT agency_name, count(agency_id) AS agency_id, max(timestamp_pgsql) AS timestamp_pgsql, count(timestamp_pgsql) filter(WHERE timestamp_pgsql >= '${day}' AND timestamp_pgsql < '`
|
|
+ tomorrow.toISOString().substring(0, 10)
|
|
+ `') AS rt_part FROM `
|
|
+ schema
|
|
+ `.vw_join_gncy_rts_trps_srvcs_pdts WHERE dates like '%${day}%' AND ((timestamp_pgsql >= '${day}' AND timestamp_pgsql < '`
|
|
+ tomorrow.toISOString().substring(0, 10)
|
|
+ `') OR timestamp_pgsql IS NULL) GROUP BY agency_name, agency_id ORDER BY agency_name ASC;`
|
|
|
|
return await db.query(query);
|
|
};
|
|
|
|
module.exports = {
|
|
get
|
|
};
|