Преглед изворни кода

Clear weather data job. Fixed bug with displaying bookmark icons on mobile devices

unknown пре 4 година
родитељ
комит
936da301b8

+ 2 - 1
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;
 }

+ 22 - 0
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;

+ 3 - 2
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();
 })