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