mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-21 12:29:36 +02:00
22 lines
427 B
JavaScript
22 lines
427 B
JavaScript
|
const { Op } = require('sequelize');
|
||
|
const Weather = require('../models/Weather');
|
||
|
|
||
|
const clearWeatherData = async () => {
|
||
|
const weather = await Weather.findOne({
|
||
|
order: [[ 'createdAt', 'DESC' ]]
|
||
|
});
|
||
|
|
||
|
if (weather) {
|
||
|
await Weather.destroy({
|
||
|
where: {
|
||
|
id: {
|
||
|
[Op.lt]: weather.id
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
console.log('Old weather data was deleted');
|
||
|
}
|
||
|
|
||
|
module.exports = clearWeatherData;
|