backend/src/services/find.services.js
Fred Boniface b1940bcfbb Removed unneccesary vars and added notes for tidyup
in preparation for testing additional info

Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-02-16 10:39:19 +00:00

59 lines
1.7 KiB
JavaScript

// Parse and return a find request
const log = require('../utils/log.utils'); // Log Helper
const db = require('../services/dbAccess.services');
const san = require('../utils/sanitizer.utils')
// DB Query: query(collection, query)
// Define collection as all queries are for the "corpus" collection.
const col = "corpus"
async function name(id){
log.out(`findServices.name: Finding station name: ${id}`)
var name = san.cleanApiEndpointTxt(id.toUpperCase())
query = {NLCDESC: name}
//var data = await db.query(col,query)
return await db.query(col,query)
}
async function crs(id){
log.out(`findServices.crs: Finding crs: ${id}`)
var crs = san.cleanApiEndpointTxt(id.toUpperCase())
query = {'3ALPHA': crs}
//var data = await db.query(col,query)
return await db.query(col,query)
}
async function nlc(id){
log.out(`findServices.nlc: Finding nlc: ${id}`)
var nlc = san.cleanApiEndpointNum(id)
query = {NLC: parseInt(nlc)}
log.out(`findServices.nlc: NLC Converted to int: ${query}`)
//var data = await db.query(col,query)
return await db.query(col,query)
}
async function tiploc(id){
log.out(`findServices.tiploc: Finding tiploc: ${id}`)
var tiploc = san.cleanApiEndpointTxt(id.toUpperCase())
query = {TIPLOC: tiploc}
//var data = await db.query(col,query)
return await db.query(col,query)
}
async function stanox(id){
log.out(`findServices.stanox: Finding stanox: ${id}`)
var stanox = san.cleanApiEndpointNum(id)
query = {STANOX: String(stanox)}
//var data = await db.query(col,query)
return await db.query(col,query)
}
module.exports = {
name,
crs,
nlc,
tiploc,
stanox
}