Created
October 21, 2018 10:58
-
-
Save gpizana/77e5983c6465350f29af0b54f53d9f4a to your computer and use it in GitHub Desktop.
StrangerTeam2018 Alert Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash') | |
const axios = require('axios'); | |
const geolib = require('geolib'); | |
const nodexml = require('nodexml'); | |
module.exports = function(config) { | |
const AemetAlerts = require('./aemet-alerts.js')(config); | |
const NasaAlerts = require('./nasa-alerts.js')(config); | |
const alertByGeoLoc = async (req, res, next) => { | |
const lat = req.params.lat; | |
const long = req.params.long; | |
try { | |
const aemetAlerts = await AemetAlerts.alertByGeoLoc (lat, long); | |
const nasaAlerts = await NasaAlerts.alertByGeoLoc (lat, long); | |
const allAlerts = [].concat (nasaAlerts, aemetAlerts); | |
return res.json(allAlerts).end(); | |
} | |
catch (err) { | |
return res.status(400).json({ | |
error: err.message | |
}); | |
} | |
} | |
const mapByGeoLoc = async (req, res, next) => { | |
const lat = req.params.lat; | |
const long = req.params.long; | |
try { | |
const mapUrl = await AemetAlerts.mapByGeoLoc (lat, long); | |
return res.json(mapUrl).end(); | |
} | |
catch (err) { | |
return res.status(400).json({ | |
error: err.message | |
}); | |
} | |
} | |
return { | |
alertByGeoLoc: alertByGeoLoc, | |
mapByGeoLoc: mapByGeoLoc | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment