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: # 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){ async function query(collection, query){
await client.connect(); await client.connect();
let qcoll = db.collection(collection); var qcoll = db.collection(collection);
let qcursor = qcoll.find(query) var qcursor = qcoll.find(query)
let qresult = await qcursor.toArray(); qcursor.project({_id: 0})
var qresult = await qcursor.toArray();
return qresult; 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'); const corpus = require('../services/corpus.services');
async function getStations(){ async function getStations(){
// Databse lookup, get list of all stations as per the Python script output var out = await db.query("stations")
return {state:"No can do, not fully implemented."}; log.out(`listServices.getStations: fetched stations list`)
return out;
} }
async function getCorpus(){ async function getCorpus(){
// Raw corpus data, currently fetches from Network Rail each time its called var out = await db.query("corpus")
return corpus.get(); log.out(`listServices.getCorpus: fetched CORPUS list`)
return out;
} }
module.exports = { module.exports = {