mirror of
https://github.com/pawelmalak/flame.git
synced 2026-02-28 01:13:11 +08:00
Created Cron job to get data from external api every 15 minutes and save it to local database. Created Weather model and controller to get latest weather status
This commit is contained in:
18
controllers/weather.js
Normal file
18
controllers/weather.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const asyncWrapper = require('../middleware/asyncWrapper');
|
||||
const ErrorResponse = require('../utils/ErrorResponse');
|
||||
const Weather = require('../models/Weather');
|
||||
|
||||
// @desc Get latest weather status
|
||||
// @route POST /api/weather
|
||||
// @access Public
|
||||
exports.getWeather = asyncWrapper(async (req, res, next) => {
|
||||
const weather = await Weather.findAll({
|
||||
order: [['createdAt', 'DESC']],
|
||||
limit: 1
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: weather
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user