From 25862137dae4b22f9a2f4a3598ae014ea23cdb12 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Thu, 28 Sep 2023 16:10:42 +0100 Subject: [PATCH] Port find.services to TS Signed-off-by: Fred Boniface --- src/services/find.services.js | 63 ----------------------------------- src/services/find.services.ts | 52 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 63 deletions(-) delete mode 100644 src/services/find.services.js create mode 100644 src/services/find.services.ts diff --git a/src/services/find.services.js b/src/services/find.services.js deleted file mode 100644 index a92c64c..0000000 --- a/src/services/find.services.js +++ /dev/null @@ -1,63 +0,0 @@ -// Parse and return a find request - -const db = require("../services/dbAccess.services"); -const san = require("../utils/sanitizer.utils"); -/* -import { query } from "../services/dbAccess.services"; -import { cleanApiEndpointTxt, cleanApiEndpointNum } from "../utils/sanitizer.utils"; -*/ -import { logger } from "../utils/logger.utils"; - -// DB Query: query(collection, query) - -// Define collection as all queries are for the "corpus" collection. -const col = "corpus"; - -async function name(id) { - logger.debug(`findServices.name: Finding station name: ${id}`); - var name = san.cleanApiEndpointTxt(id.toUpperCase()); - let query = { NLCDESC: name }; - //var data = await db.query(col,query) - return await db.query(col, query); -} - -async function crs(id) { - logger.debug(`findServices.crs: Finding crs: ${id}`); - var crs = san.cleanApiEndpointTxt(id.toUpperCase()); - let query = { "3ALPHA": crs }; - //var data = await db.query(col,query) - return await db.query(col, query); -} - -async function nlc(id) { - logger.debug(`findServices.nlc: Finding nlc: ${id}`); - var nlc = san.cleanApiEndpointNum(id); - let query = { NLC: parseInt(nlc) }; - logger.trace(`findServices.nlc: NLC Converted to int: ${query}`); - //var data = await db.query(col,query) - return await db.query(col, query); -} - -async function tiploc(id) { - logger.debug(`findServices.tiploc: Finding tiploc: ${id}`); - var tiploc = san.cleanApiEndpointTxt(id.toUpperCase()); - let query = { TIPLOC: tiploc }; - //var data = await db.query(col,query) - return await db.query(col, query); -} - -async function stanox(id) { - logger.debug(`findServices.stanox: Finding stanox: ${id}`); - var stanox = san.cleanApiEndpointNum(id); - let query = { STANOX: String(stanox) }; - //var data = await db.query(col,query) - return await db.query(col, query); -} - -module.exports = { - name, - crs, - nlc, - tiploc, - stanox, -}; diff --git a/src/services/find.services.ts b/src/services/find.services.ts new file mode 100644 index 0000000..5f1f2ac --- /dev/null +++ b/src/services/find.services.ts @@ -0,0 +1,52 @@ +// Parse and return a find request + +import { query } from "../services/dbAccess.services"; +import { cleanApiEndpointTxt, cleanApiEndpointNum } from "../utils/sanitizer.utils"; +import { logger } from "../utils/logger.utils"; + +// Define collection as all queries are for the "corpus" collection. +const col: string = "corpus"; + +async function name(id: string) { + logger.debug(`findServices.name: Finding station name: ${id}`); + var name = cleanApiEndpointTxt(id.toUpperCase()); + let queryObj = { NLCDESC: name }; + return await query(col, queryObj); +} + +async function crs(id: string) { + logger.debug(`findServices.crs: Finding crs: ${id}`); + var crs = cleanApiEndpointTxt(id.toUpperCase()); + let queryObj = { "3ALPHA": crs }; + return await query(col, queryObj); +} + +async function nlc(id: string) { + logger.debug(`findServices.nlc: Finding nlc: ${id}`); + var nlc = cleanApiEndpointNum(id); + let queryObj = { NLC: parseInt(nlc) }; + logger.trace(`findServices.nlc: NLC Converted to int: ${query}`); + return await query(col, queryObj); +} + +async function tiploc(id: string) { + logger.debug(`findServices.tiploc: Finding tiploc: ${id}`); + var tiploc = cleanApiEndpointTxt(id.toUpperCase()); + let queryObj = { TIPLOC: tiploc }; + return await query(col, queryObj); +} + +async function stanox(id: string) { + logger.debug(`findServices.stanox: Finding stanox: ${id}`); + var stanox = cleanApiEndpointNum(id); + let queryObj = { STANOX: String(stanox) }; + return await query(col, queryObj); +} + +module.exports = { + name, + crs, + nlc, + tiploc, + stanox, +};