2021-05-17 16:23:54 +00:00
|
|
|
const asyncWrapper = require('../middleware/asyncWrapper');
|
|
|
|
const ErrorResponse = require('../utils/ErrorResponse');
|
|
|
|
const Weather = require('../models/Weather');
|
2021-06-07 10:17:10 +00:00
|
|
|
const getExternalWeather = require('../utils/getExternalWeather');
|
2021-05-17 16:23:54 +00:00
|
|
|
|
|
|
|
// @desc Get latest weather status
|
2021-06-07 10:17:10 +00:00
|
|
|
// @route GET /api/weather
|
2021-05-17 16:23:54 +00:00
|
|
|
// @access Public
|
|
|
|
exports.getWeather = asyncWrapper(async (req, res, next) => {
|
|
|
|
const weather = await Weather.findAll({
|
|
|
|
order: [['createdAt', 'DESC']],
|
|
|
|
limit: 1
|
|
|
|
});
|
|
|
|
|
2021-06-07 10:17:10 +00:00
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: weather
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// @desc Update weather
|
|
|
|
// @route GET /api/weather/update
|
|
|
|
// @access Public
|
|
|
|
exports.updateWeather = asyncWrapper(async (req, res, next) => {
|
|
|
|
const weather = await getExternalWeather();
|
|
|
|
|
2021-05-17 16:23:54 +00:00
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: weather
|
|
|
|
})
|
|
|
|
})
|