Skip to content

Commit

Permalink
fix: fixing the api filters
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSloanRanger committed Feb 1, 2024
1 parent 50aaf8e commit 3842416
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
48 changes: 21 additions & 27 deletions api/atmRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,27 @@ router.get("/api/atms", async (req, res) => {

router.post("/api/atms/filter", async (req, res) => {
try {
const defaultAccessibility = ["AudioCashMachine", "WheelchairAccess"];
const defaultATMServices = [
"CashWithdrawal",
"CashDeposits",
"PINChange",
"ChequeDeposits",
"Balance",
];

const atms = await db
.collection("ATMs")
.find({
Accessibility: {
$all: req.body.Accessibility
? req.body.Accessibility
: ["AudioCashMachine", "WheelchairAccess"],
},
ATMServices: {
$all: req.body.ATMServices,
},
ATMServices: {
$all: req.body.ATMServices
? req.body.ATMServices
: [
"CashWithdrawal",
"CashDeposits",
"PINChange",
"ChequeDeposits",
"Balance",
],
Accessibility: req.body.Accessibility
? { $all: req.body.Accessibility }
: { $exists: true, $ne: null },
ATMServices: req.body.ATMServices
? { $all: req.body.ATMServices }
: { $exists: true, $ne: null },
Access24HoursIndicator: {
$in: [req.body.Access24HoursIndicator, true, false],
},
Access24HoursIndicator: req.body.Access24HoursIndicator
? req.body.Access24HoursIndicator
: {
$in: [true, false],
},
$and: [
{
$expr: {
Expand All @@ -65,12 +59,12 @@ router.post("/api/atms/filter", async (req, res) => {
},
{
$expr: {
$lt: [
req.body.Latitude - req.body.Radius / 111,
$gt: [
{
$toDouble:
"$Location.PostalAddress.GeoLocation.GeographicCoordinates.Latitude",
},
req.body.Latitude - req.body.Radius / 111,
],
},
},
Expand All @@ -87,12 +81,12 @@ router.post("/api/atms/filter", async (req, res) => {
},
{
$expr: {
$lt: [
req.body.Longitude - req.body.Radius / 111,
$gt: [
{
$toDouble:
"$Location.PostalAddress.GeoLocation.GeographicCoordinates.Longitude",
},
req.body.Longitude - req.body.Radius / 111,
],
},
},
Expand Down
26 changes: 8 additions & 18 deletions api/branchRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,15 @@ router.get("/api/branches", async (req, res) => {

router.post("/api/branches/filter", async (req, res) => {
try {
const atms = await db
const branches = await db
.collection("Branches")
.find({
Accessibility: {
$all: req.body.Accessibility
? req.body.Accessibility
: [
"WheelchairAccess",
"LowerLevelCounter",
"LevelAccess",
"InductionLoop",
"AutomaticDoors",
],
},
ServiceAndFacility: {
$all: req.body.ServiceAndFacility
? req.body.ServiceAndFacility
: ["WiFi"],
},
Accessibility: req.body.Accessibility
? { $all: req.body.Accessibility }
: { $exists: true, $ne: null },
ServiceAndFacility: req.body.ServiceAndFacility
? { $all: req.body.ServiceAndFacility }
: { $exists: true, $ne: null },
$and: [
{
$expr: {
Expand Down Expand Up @@ -91,7 +81,7 @@ router.post("/api/branches/filter", async (req, res) => {
],
})
.toArray();
res.json(atms);
res.json(branches);
} catch (error) {
handleError(res, error);
}
Expand Down

0 comments on commit 3842416

Please sign in to comment.