@@ -179,10 +179,11 @@ async function getReasonCode(code) {
|
||||
}
|
||||
|
||||
async function getNearestStations(lat, long) {
|
||||
|
||||
logger.debug(`ldbService.getNearestStations: Fetching nearest stations`)
|
||||
let pipeline = findStationsByDistancePipeline(4, lat, long)
|
||||
try {
|
||||
return await db.queryAggregate(pipeline)
|
||||
return await db.queryAggregate("stations", pipeline)
|
||||
} catch (err) {
|
||||
logger.error(err, `ldbService.getNearestStations`)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export function findStationsByDistancePipeline(count: number, latitude: number, longitude: number) {
|
||||
return [
|
||||
export function findStationsByDistancePipeline(count: number, latitude: string, longitude: string) {
|
||||
const numericLatitude = parseFloat(latitude)
|
||||
const numericLongitude = parseFloat(longitude)
|
||||
const pipeline = [
|
||||
{
|
||||
'$geoNear': {
|
||||
'near': {
|
||||
'type': 'Point',
|
||||
'coordinates': [
|
||||
longitude, latitude
|
||||
numericLongitude, numericLatitude
|
||||
]
|
||||
},
|
||||
'distanceField': 'distance'
|
||||
@@ -39,4 +41,7 @@ export function findStationsByDistancePipeline(count: number, latitude: number,
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
//console.log(JSON.stringify(pipeline))
|
||||
return pipeline
|
||||
}
|
||||
Reference in New Issue
Block a user