Furhter work on trainSErvice endpoint
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
d879d544fe
commit
c0f0591866
1
app.js
1
app.js
@ -29,6 +29,7 @@ const issueRtr = require('./src/routes/issue.routes');
|
|||||||
const statRtr = require('./src/routes/stats.routes');
|
const statRtr = require('./src/routes/stats.routes');
|
||||||
const regRtr = require('./src/routes/registration.routes');
|
const regRtr = require('./src/routes/registration.routes');
|
||||||
const pisRtr = require('./src/routes/pis.routes');
|
const pisRtr = require('./src/routes/pis.routes');
|
||||||
|
const trainRtr = require('./src/routes/train.routes');
|
||||||
|
|
||||||
// Set Server Configurations
|
// Set Server Configurations
|
||||||
const srvListen = process.env.OWL_SRV_LISTEN || '0.0.0.0';
|
const srvListen = process.env.OWL_SRV_LISTEN || '0.0.0.0';
|
||||||
|
@ -16,12 +16,17 @@ async function findByHeadcodeToday(headcode) {
|
|||||||
daysRun: {$in: [shortDay]}
|
daysRun: {$in: [shortDay]}
|
||||||
};
|
};
|
||||||
const queryData = await db.query('timetable', query);
|
const queryData = await db.query('timetable', query);
|
||||||
console.log(JSON.stringify(queryData));
|
|
||||||
let trainData = await parseTrains(queryData);
|
let trainData = await parseTrains(queryData);
|
||||||
let preparedData = [];
|
let preparedData = [];
|
||||||
for (const trainService in trainData) {
|
for (let trainService in trainData) {
|
||||||
// Search for PIS Code for each service
|
// Search for PIS Code for each service
|
||||||
|
console.log(JSON.stringify(trainData));
|
||||||
|
// tiplocList seems to be empty - trainData[trainService] is an array, should be an object!
|
||||||
|
// Check the parseTrains it seems to be encapsulating an array in an array.
|
||||||
|
// meaning that trainData[trainService]['stops'] doesn't exist.
|
||||||
|
// I THINK: the findByTrainUid function should return a single object rather than an array
|
||||||
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
|
const tiplocList = await getPublicStops(trainData[trainService]['stops']);
|
||||||
|
//console.log(tiplocList.length); console.log(tiplocList);
|
||||||
if (tiplocList.length) {
|
if (tiplocList.length) {
|
||||||
const pisDetail = await pis.findByTiplocArray(tiplocList);
|
const pisDetail = await pis.findByTiplocArray(tiplocList);
|
||||||
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
|
trainData[trainService]['pis'] = pisDetail?.[0]?.['code'] ?? 'None';
|
||||||
@ -52,7 +57,6 @@ async function getPublicStops(data) {
|
|||||||
async function parseTrains(data) { // Takes a single days data from a headcode query and returns only relevant services
|
async function parseTrains(data) { // Takes a single days data from a headcode query and returns only relevant services
|
||||||
let trainUids = [];
|
let trainUids = [];
|
||||||
for (const i of data) {
|
for (const i of data) {
|
||||||
console.log(i);
|
|
||||||
const trainUid = i['trainUid'];
|
const trainUid = i['trainUid'];
|
||||||
if (!trainUids.includes(trainUid)) {
|
if (!trainUids.includes(trainUid)) {
|
||||||
trainUids.push(trainUid);
|
trainUids.push(trainUid);
|
||||||
@ -101,7 +105,6 @@ async function findByTrainUid(uid, date = new Date()) { // Date defaults to toda
|
|||||||
stpIndicators[trainUid].hasP = true;
|
stpIndicators[trainUid].hasP = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(stpIndicators));
|
|
||||||
let preparedData = [];
|
let preparedData = [];
|
||||||
for (const serviceDetail of queryData) {
|
for (const serviceDetail of queryData) {
|
||||||
const trainUid = serviceDetail['trainUid'];
|
const trainUid = serviceDetail['trainUid'];
|
||||||
|
Loading…
Reference in New Issue
Block a user