Skip to content

Commit

Permalink
Merge pull request #46 from wearefuturegov/develop
Browse files Browse the repository at this point in the history
Staging deploy
  • Loading branch information
apricot13 authored Jun 24, 2024
2 parents 8778b94 + 9d40755 commit 6abc0c4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .docker/services/mongo/setup-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ db.indexed_services.createIndex(
}
)
db.indexed_services.createIndex({
"locations.geometry": "2dsphere",
"service_at_locations.location.geometry": "2dsphere",
})
db.indexed_services.createIndex({
"taxonomies.slug": 1,
Expand Down
6 changes: 4 additions & 2 deletions __tests__/unit/lib/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("locationGeometry", () => {
const lat = "40.7128"
const lng = "-74.0060"
const expectedQuery = {
"locations.geometry": {
"service_at_locations.location.geometry": {
$nearSphere: {
$geometry: {
type: "Point",
Expand Down Expand Up @@ -203,7 +203,9 @@ describe("filterAccessibilities", () => {
"wheelchair-accessible-entrance",
]
const expectedQuery = {
"locations.accessibilities.slug": { $in: accessibilities },
"service_at_locations.location.accessibilities.slug": {
$in: accessibilities,
},
}
expect(filters.filterAccessibilities(accessibilities)).toEqual(
expectedQuery
Expand Down
41 changes: 41 additions & 0 deletions docker-compose.with-outpost.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# if you want to use the Outpost API in dev mode with outpost in dev mode, you can use this file to start the service.
# Run outpost as normal and then use this docker compose file to tag along
# docker compose -f docker-compose.with-outpost.yml up -d

version: "3.7"
services:
# Outpost api

app:
image: "outpost_api:development"
build:
context: .
# uncomment for 'prod' like env locally
# NODE_ENV: production
container_name: outpost-api-service
# use if you just want to keep the container running
# entrypoint: ["tail"]
# command: ["-f", "/dev/null"]
environment:
DB_URI: mongodb://${MONGO_INITDB_USERNAME:-outpost}:${MONGO_INITDB_PASSWORD:-password}@host.docker.internal:27018/${MONGO_INITDB_DATABASE:-outpost_api_development}
platform: linux/arm64
volumes:
- ./:/app:cached
- /app/node_modules
ports:
- 3002:3000
networks:
- outpost_internal_network
- outpost_external_network
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/health"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s

networks:
outpost_internal_network:
external: true
outpost_external_network:
external: true
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ It needs the right indices on the MongoDB collection to enable full-text and geo

```
db.indexed_services.createIndex({ name: "text", description: "text" })
db.indexed_services.createIndex({ "locations.coordinates": "2dsphere" })
db.indexed_services.createIndex({ "service_at_locations.location.geometry": "2dsphere" })
```

You can create these two, plus an index of taxonomy slugs, automatically with the `npm run prepare-indices` command.
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/v1/services/routes/get-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ module.exports = {
createCountQuery: query => {
// "budget deep clone" we spread $and so can modify it for countQuery only
const countQuery = { ...query, $and: [...query.$and] }
if ("locations.geometry" in countQuery) {
delete countQuery["locations.geometry"]
if ("service_at_locations.location.geometry" in countQuery) {
delete countQuery["service_at_locations.location.geometry"]

countQuery["$and"].push({
"locations.geometry": {
"service_at_locations.location.geometry": {
$exists: true,
$ne: null,
},
Expand Down
10 changes: 8 additions & 2 deletions src/lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
locationGeometry: (lat, lng) => {
let query = {}
if (lat && lng) {
query["locations.geometry"] = {
query["service_at_locations.location.geometry"] = {
// use this option to search within a defined area
// remember if you take out nearsphere to update the executeQuery function!
// this lets us get accurate result counts
// $geoWithin: {
Expand All @@ -14,11 +15,14 @@ module.exports = {
// ],
// },
// but this is how its always been done so we will keep this for now
// added maxDistance to limit the search to 15 miles for efficiency
// nb if you add in $maxDistance you will need to update the createCountQuery function workaround
$nearSphere: {
$geometry: {
type: "Point",
coordinates: [parseFloat(lng), parseFloat(lat)],
},
// $maxDistance: 10 * 1609.34, // miles x 1609.34 = Distance in meters
},
}
}
Expand Down Expand Up @@ -202,7 +206,9 @@ module.exports = {
filterAccessibilities: accessibilities => {
if (accessibilities?.length > 0) {
return {
"locations.accessibilities.slug": { $in: accessibilities },
"service_at_locations.location.accessibilities.slug": {
$in: accessibilities,
},
}
}
return {}
Expand Down
2 changes: 1 addition & 1 deletion utils/prepare-indices.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ connect(async db => {
}
)
await db.collection("indexed_services").createIndex({
"locations.geometry": "2dsphere",
"service_at_locations.location.geometry": "2dsphere",
})
await db.collection("indexed_services").createIndex({
"taxonomies.slug": 1,
Expand Down

0 comments on commit 6abc0c4

Please sign in to comment.