From 936da301b82d4d035025d168066ecacf49a36e79 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Jun 2021 01:51:59 +0200 Subject: [PATCH] Clear weather data job. Fixed bug with displaying bookmark icons on mobile devices --- .../BookmarkCard/BookmarkCard.module.css | 3 ++- utils/clearWeatherData.js | 22 +++++++++++++++++++ utils/jobs.js | 5 +++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 utils/clearWeatherData.js diff --git a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css index 4f11ca8..b21ed42 100644 --- a/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css +++ b/client/src/components/Bookmarks/BookmarkCard/BookmarkCard.module.css @@ -28,7 +28,8 @@ .BookmarkIcon { width: 20px; + height: 20px; display: flex; - margin-bottom: 1px; + margin-top: 3px; margin-right: 2px; } \ No newline at end of file diff --git a/utils/clearWeatherData.js b/utils/clearWeatherData.js new file mode 100644 index 0000000..d43f975 --- /dev/null +++ b/utils/clearWeatherData.js @@ -0,0 +1,22 @@ +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; \ No newline at end of file diff --git a/utils/jobs.js b/utils/jobs.js index aa8d41c..19dc0a8 100644 --- a/utils/jobs.js +++ b/utils/jobs.js @@ -1,5 +1,6 @@ const schedule = require('node-schedule'); const getExternalWeather = require('./getExternalWeather'); +const clearWeatherData = require('./clearWeatherData'); const Sockets = require('../Sockets'); // Update weather data every 15 minutes @@ -14,6 +15,6 @@ const weatherJob = schedule.scheduleJob('updateWeather', '0 */15 * * * *', async }) // Clear old weather data every 4 hours -const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 0 */4 * * *', async () => { - console.log('clean') +const weatherCleanerJob = schedule.scheduleJob('clearWeather', '0 5 */4 * * *', async () => { + clearWeatherData(); }) \ No newline at end of file