list.services now queries DB

This commit is contained in:
Fred Boniface 2023-01-11 13:34:24 +00:00
parent bc23a976f9
commit dac9adf666
3 changed files with 13 additions and 8 deletions

View File

@ -1,3 +1,3 @@
# What to do next:
* Ensure existing 'meta' entries are updated and new entries aren't made.
* List services changed to read from db rather than request fresh data each time.

View File

@ -75,9 +75,10 @@ async function updateMeta(type, target, unixTime){
async function query(collection, query){
await client.connect();
let qcoll = db.collection(collection);
let qcursor = qcoll.find(query)
let qresult = await qcursor.toArray();
var qcoll = db.collection(collection);
var qcursor = qcoll.find(query)
qcursor.project({_id: 0})
var qresult = await qcursor.toArray();
return qresult;
}

View File

@ -1,13 +1,17 @@
const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services')
const corpus = require('../services/corpus.services');
async function getStations(){
// Databse lookup, get list of all stations as per the Python script output
return {state:"No can do, not fully implemented."};
var out = await db.query("stations")
log.out(`listServices.getStations: fetched stations list`)
return out;
}
async function getCorpus(){
// Raw corpus data, currently fetches from Network Rail each time its called
return corpus.get();
var out = await db.query("corpus")
log.out(`listServices.getCorpus: fetched CORPUS list`)
return out;
}
module.exports = {