From 1f59ccfb2c87eeb4583b1748eff601c796642423 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Sun, 6 Aug 2023 10:48:24 +0300 Subject: [PATCH] cleaning --- src/index.ts | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3424953..1688496 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,30 +17,39 @@ class App { async startCronJob() { console.log("START CRON JOB"); - + const newGamesAdded = []; await this.googleCalendar.init(); // Schedule the job to run daily at a specific time (e.g., 1:00 AM) - try { - const games = await app.gameSource.getGamesFromHaifa(); + try { + const games = await app.gameSource.getGamesFromHaifa(); - for (const game of games) { - const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent( - game.start.dateTime, - game.end.dateTime, - game.summary - ); + for (const game of games) { + const isDuplicateEvent = await this.googleCalendar.isDuplicateEvent( + game.start.dateTime, + game.end.dateTime, + game.summary + ); - if (!isDuplicateEvent) { - console.log("Event does not exist"); - await this.googleCalendar.updateNewEvent([game]); - } else { - console.log("Event already exists"); - } + if (!isDuplicateEvent) { + newGamesAdded.push(game); + console.log("Event does not exist"); + await this.googleCalendar.updateNewEvent([game]); + } else { + console.log("Event already exists"); + console.log("Event:"); + console.log("Happening at:"); } - } catch (error) { - console.error("Error in cron job:", error.message); } + + if(newGamesAdded.length > 0) { + console.log("New games added:", newGamesAdded); + } else { + console.log("No new games added"); + } + } catch (error) { + console.error("Error in cron job:", error.message); + } } }