TimetableAPI-Upgrade #64
1
app.js
1
app.js
@ -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",
|
||||||
|
@ -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 = {
|
||||||
|
Loading…
Reference in New Issue
Block a user