feat: add API route trips-by-route-day
This commit is contained in:
parent
4822705aa3
commit
2b81926861
|
@ -99,7 +99,7 @@ const numberOfTrips = require('./route/number-of-trips');
|
|||
//get routes belonging to the same agency_id
|
||||
const routesByAgencyId = require('./route/routes-by-agency-id');
|
||||
|
||||
//get all service dates by service_id (including exceptions)
|
||||
//get all service dates by service_id (including additions and exceptions)
|
||||
const serviceAvailability=require('./route/service-availability');
|
||||
|
||||
//get service availability for all trips belonging to the specified route_id
|
||||
|
@ -127,6 +127,9 @@ const TRIPSROUTER = require('./route/trips');
|
|||
//get all trips that belong to the specified route_id
|
||||
const tripsByRouteId = require('./route/trips-by-route-id');
|
||||
|
||||
//get trips by route_id and day YYY-M(M)-D(D)
|
||||
const tripsByRouteDay = require('./route/trips-by-route-day');
|
||||
|
||||
//get overall trip counts for calendar dates that belong to the specified route_id
|
||||
const tripCalendarByRouteId = require('./route/trip-calendar-by-route-id');
|
||||
|
||||
|
@ -222,6 +225,7 @@ APP.use('/trip-count-day-agency', tripCountDayAgency);
|
|||
APP.use('/trip-count-day-route', tripCountDayRoute);
|
||||
APP.use('/trip-calendar-by-agency-id', tripCalendarByAgencyId);
|
||||
APP.use('/trip-calendar-by-route-id', tripCalendarByRouteId);
|
||||
APP.use('/trips-by-route-day', tripsByRouteDay);
|
||||
//service
|
||||
APP.use('/service', ROUTESERVICE);
|
||||
/** TODO Disable this route as it is not working!
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const debug=require('debug')('debug');
|
||||
debug('services-by-route-id start...');
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const serviceByRouteId = require('../service/services-by-route-id');
|
||||
const utils=require('../utils');
|
||||
|
||||
router.get('/', async function(req, res, next) {
|
||||
try {
|
||||
res.json(await serviceByRouteId.get(req.query.routeid));
|
||||
|
@ -14,4 +14,3 @@ router.get('/', async function(req, res, next) {
|
|||
});
|
||||
|
||||
module.exports = router;
|
||||
debug('services-by-route-id done.');
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tripsByRouteDay = require('../service/trips-by-route-day');
|
||||
const utils=require('../utils');
|
||||
|
||||
router.get('/', async function(req, res, next) {
|
||||
try {
|
||||
res.json(await tripsByRouteDay.get(req.query.routeid, req.query.day));
|
||||
} catch (err) {
|
||||
console.error(`Error while getting trips by route_id and day, msg: `, err.message);
|
||||
res.status(err.statusCode || 500).json(utils.MSGS.error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -1,21 +1,29 @@
|
|||
const debug=require('debug')('debug');
|
||||
//debug('services-by-route-id start...');
|
||||
require('dotenv').config();
|
||||
|
||||
const db = require('./db');
|
||||
const mapping=require('../utils/mapping');
|
||||
|
||||
async function get(routeid = 0) {
|
||||
//debug('services-by-route-id start...');
|
||||
//debug('routeid: '+routeid);
|
||||
const QUERY=`SELECT trips.service_id FROM trips WHERE trips.route_id='${routeid}';`
|
||||
//debug('QUERY: '+QUERY);
|
||||
const aryServiceIds = await db.query(QUERY);
|
||||
debug('services-by-route-id aryServiceIds.length: '+aryServiceIds.length);
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
//debug('schema: ' + schema );
|
||||
|
||||
const query = `SELECT trips.service_id FROM ` + schema + `.trips WHERE trips.route_id='${routeid}';`
|
||||
//debug('query: '+query);
|
||||
|
||||
const aryServiceIds = await db.query(query);
|
||||
//debug('services-by-route-id aryServiceIds.length: '+aryServiceIds.length);
|
||||
|
||||
const setServiceIds=new Set();
|
||||
aryServiceIds.forEach(value=>setServiceIds.add(value.service_id));
|
||||
|
||||
//debug('services-by-route-id setServiceIds.size: '+setServiceIds.size);
|
||||
return mapping.set2Array(setServiceIds);
|
||||
debug('services-by-route-id setServiceIds.size: '+setServiceIds.size);
|
||||
return aryServiceIds;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
}
|
||||
//debug('services-by-route-id done.');
|
||||
};
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
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-2-29') {
|
||||
|
||||
const schema = process.env.DB_SCHEMA || 'schema';
|
||||
const query = `SELECT trip_id, trip_short_name, trip_headsign FROM ` + schema + `.vw_join_rts_trps_srvcs WHERE dates like '%${day}%' and route_id = '${routeid}';`
|
||||
|
||||
return await db.query(query);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
};
|
Loading…
Reference in New Issue