2021-06-10 01:51:59 +02:00
|
|
|
const { Op } = require('sequelize');
|
|
|
|
const Weather = require('../models/Weather');
|
2021-06-22 14:49:00 +02:00
|
|
|
const Logger = require('./Logger');
|
|
|
|
const logger = new Logger();
|
2021-06-10 01:51:59 +02:00
|
|
|
|
|
|
|
const clearWeatherData = async () => {
|
|
|
|
const weather = await Weather.findOne({
|
|
|
|
order: [[ 'createdAt', 'DESC' ]]
|
|
|
|
});
|
|
|
|
|
|
|
|
if (weather) {
|
|
|
|
await Weather.destroy({
|
|
|
|
where: {
|
|
|
|
id: {
|
|
|
|
[Op.lt]: weather.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-22 14:49:00 +02:00
|
|
|
logger.log('Old weather data was deleted');
|
2021-06-10 01:51:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = clearWeatherData;
|