Compare commits

..

3 Commits

Author SHA1 Message Date
Fred Boniface 45fdf1904d Add pipeline for partial PIS match
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-10-12 21:56:58 +01:00
Fred Boniface 7503722d84 Prettier
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-10-12 21:56:46 +01:00
Fred Boniface 59a75f811d Disable auth for development
Signed-off-by: Fred Boniface <fred@fjla.uk>
2023-10-12 21:56:11 +01:00
8 changed files with 65 additions and 11 deletions

1
app.js
View File

@ -72,7 +72,6 @@ app.use("/api/v2/timetable", tt2Rtr); // API Version 2
app.use("/api/v2/user", user2Rtr); // API Version 2 app.use("/api/v2/user", user2Rtr); // API Version 2
app.use("/misc", miscRtr); // Non public-api endpoints (Stats, Issue, etc.) app.use("/misc", miscRtr); // Non public-api endpoints (Stats, Issue, etc.)
app.use("/api/v1/auth/test", authenticate, (req, res) => app.use("/api/v1/auth/test", authenticate, (req, res) =>
res.status(200).json({ res.status(200).json({
status: "ok", status: "ok",

8
package-lock.json generated
View File

@ -24,7 +24,7 @@
"zlib": "^1.0.5" "zlib": "^1.0.5"
}, },
"devDependencies": { "devDependencies": {
"@owlboard/ts-types": "^0.0.9", "@owlboard/ts-types": "^0.1.0",
"@types/jest": "^29.5.3", "@types/jest": "^29.5.3",
"eslint": "^8.39.0", "eslint": "^8.39.0",
"jest": "^29.6.2", "jest": "^29.6.2",
@ -1983,9 +1983,9 @@
} }
}, },
"node_modules/@owlboard/ts-types": { "node_modules/@owlboard/ts-types": {
"version": "0.0.9", "version": "0.1.0",
"resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.0.9/ts-types-0.0.9.tgz", "resolved": "https://git.fjla.uk/api/packages/OwlBoard/npm/%40owlboard%2Fts-types/-/0.1.0/ts-types-0.1.0.tgz",
"integrity": "sha512-kdystFqrfj6SF8jchv4OoaBIFfJF4YoM7m09POZfuEWrdj69IXZG41k0cfYadft1wZs8L6mcZIunu8t/S5Q82Q==", "integrity": "sha512-5dLkm1wEimiv+pr5wuJbJvPfSek9WuApl/4SBwoFXVO2bmAIktFIHi+bznXKnhW9a7nJwX/w+bVwwJpBOI3I1g==",
"dev": true, "dev": true,
"license": "GPL-3.0-or-later" "license": "GPL-3.0-or-later"
}, },

View File

@ -12,6 +12,7 @@
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"run": "tsc && node dist/app.js", "run": "tsc && node dist/app.js",
"dev": "NODE_ENV=development tsc && node dist/app.js",
"start": "node app.js", "start": "node app.js",
"test": "jest", "test": "jest",
"format": "npx prettier -w ." "format": "npx prettier -w ."

View File

@ -48,7 +48,6 @@ async function random(req, res, next) {
} }
module.exports = { module.exports = {
byOrigDest,
byStartEndCRS, byStartEndCRS,
byCode, byCode,
random, random,

View File

@ -23,7 +23,6 @@ async function statistics(req, res, next) {
} }
module.exports = { module.exports = {
get,
versions, versions,
statistics, statistics,
}; };

View File

@ -4,6 +4,11 @@ const logger = require("../utils/logger.utils");
module.exports = async function authCheck(req, res, next) { module.exports = async function authCheck(req, res, next) {
//log.out("authMiddlewares: Checking authentication", "dbug"); //log.out("authMiddlewares: Checking authentication", "dbug");
logger.logger.debug("Auth check starting"); logger.logger.debug("Auth check starting");
if (process.env.NODE_ENV === "development") {
logger.logger.warn("DEVELOPMENT MODE - AUTHENTICATION DISABLED")
res.isAuthed = true;
return next()
}
try { try {
var uuid = req.headers.uuid; var uuid = req.headers.uuid;
} catch (err) { } catch (err) {

View File

@ -4,6 +4,7 @@ const db = require("../services/dbAccess.services");
const clean = require("../utils/sanitizer.utils"); const clean = require("../utils/sanitizer.utils");
import { logger } from "../utils/logger.utils"; import { logger } from "../utils/logger.utils";
import { queryAggregate } from "./dbAccess.services";
const supported = ["GW", "UK"]; const supported = ["GW", "UK"];
@ -47,19 +48,66 @@ async function findByTiplocArray(tiplocArray: string[]) {
}; };
const res = await db.query("pis", query); const res = await db.query("pis", query);
// If res is empty then try to find partial match // If res is empty then try to find partial match
/* if (res.length) { if (res.length) {
return res; return res;
} else { } else {
let partial = await findPartialMatchByTiploc(tiplocArray); let partial = await findPartialMatchByTiploc(tiplocArray);
return partial return partial
} */ }
return await res;
} }
async function findPartialMatchByTiploc(tiplocArray: string[]) { async function findPartialMatchByTiploc(tiplocArray: string[]) {
// Do some magic here, similar to findPisByOrigDest but // Do some magic here, similar to findPisByOrigDest but
// ensuring that the stops in the array match the last // ensuring that the stops in the array match the last
// x number of items in the array. // x number of items in the array.
const pipeline = [
{
$addFields: {
reversedStops: {
$reverseArray: "$stops",
},
reversedQueryArray: {
$reverseArray: tiplocArray,
},
},
},
{
$match: {
$expr: {
$gt: [
{
$indexOfArray: [
"$reversedStops",
{
$arrayElemAt: ["$reversedQueryArray", 0],
}
],
},
-1,
],
},
},
},
{
$project: {
code: 1,
skipStops: {
$subtract: [
{
$size: "$stops",
},
{
$size: tiplocArray,
},
],
},
},
},
];
const res = await queryAggregate('pis', pipeline)
console.log(JSON.stringify(res))
} }
module.exports = { module.exports = {

View File

@ -111,7 +111,10 @@ function transformTrainServices(input: any): TrainServices[] {
function checkIsSupressed(service: TrainServices): string | undefined { function checkIsSupressed(service: TrainServices): string | undefined {
logger.trace("utils/translators/ldb/staffStation.checkIsSupressed: Running"); logger.trace("utils/translators/ldb/staffStation.checkIsSupressed: Running");
if (service.serviceIsSupressed === "true" || service.isPassengerService === "false") { if (
service.serviceIsSupressed === "true" ||
service.isPassengerService === "false"
) {
return "true"; return "true";
} else { } else {
return undefined; return undefined;