From 610c9da9868decf59a4ee20f95db677804dbd0ca Mon Sep 17 00:00:00 2001 From: john-tco Date: Tue, 24 Oct 2023 12:56:24 +0100 Subject: [PATCH] revert and fix cursed bind commit --- src/notifications/notifications.service.ts | 1 - .../v2/notifications.grant.service.ts | 12 +++---- src/notifications/v2/notifications.service.ts | 31 ++++--------------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index 9ee575f..7486eff 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -55,7 +55,6 @@ export class NotificationsService { async processGrantUpdatedNotifications() { console.log('Running Process Grant Updated Notifications...'); - console.log('Running Process Grant Updated Notifications.. OLD ONE.'); const reference = `${ this.GRANT_UPDATED_TEMPLATE_ID }-${new Date().toISOString()}`; diff --git a/src/notifications/v2/notifications.grant.service.ts b/src/notifications/v2/notifications.grant.service.ts index 43ddd37..9a0a14a 100644 --- a/src/notifications/v2/notifications.grant.service.ts +++ b/src/notifications/v2/notifications.grant.service.ts @@ -182,7 +182,7 @@ export class GrantNotificationsService { } }; - async processGrantUpdatedNotifications() { + processGrantUpdatedNotifications = async () => { console.log('Running Process Grant Updated Notifications...'); const grantIds = await this.grantService.findAllUpdatedGrants(); @@ -215,9 +215,9 @@ export class GrantNotificationsService { 'en-US': false, }, }); - } + }; - async processGrantUpcomingNotifications() { + processGrantUpcomingNotifications = async () => { console.log('Running Process Grant Upcoming Notifications...'); const grants = [ ...(await this.grantService.findAllUpcomingClosingGrants()), @@ -248,9 +248,9 @@ export class GrantNotificationsService { ); } } - } + }; - async processNewGrantsNotifications() { + processNewGrantsNotifications = async () => { console.log('Running Process New Grants Notifications...'); const last7days = DateTime.now().minus({ days: 7 }).startOf('day'); @@ -275,5 +275,5 @@ export class GrantNotificationsService { await this.sendNewGrantsEmailsToBatch(batch, last7days); } } - } + }; } diff --git a/src/notifications/v2/notifications.service.ts b/src/notifications/v2/notifications.service.ts index 79ef11a..a4efa2b 100644 --- a/src/notifications/v2/notifications.service.ts +++ b/src/notifications/v2/notifications.service.ts @@ -16,38 +16,19 @@ export class v2NotificationsService { private schedularRegistry: SchedulerRegistry, ) {} - async processGrantUpdatedNotifications() { - return this.v2GrantService.processGrantUpdatedNotifications(); - } - - async processGrantUpcomingNotifications() { - return this.v2GrantService.processGrantUpcomingNotifications(); - } - - async processNewGrantsNotifications() { - return this.v2GrantService.processNewGrantsNotifications(); - } - - async processSavedSearchMatches() { - return this.v2SavedSearchService.processSavedSearchMatches(); - } - - async processSavedSearchMatchesNotifications() { - return this.v2SavedSearchService.processSavedSearchMatchesNotifications(); - } - async processScheduledJob({ timer, type }: ScheduledJob, index: number) { const CRON_JOB_MAP = { [ScheduledJobType.GRANT_UPDATED]: - this.processGrantUpdatedNotifications.bind(this), + this.v2GrantService.processGrantUpdatedNotifications, [ScheduledJobType.GRANT_UPCOMING]: - this.processGrantUpcomingNotifications.bind(this), + this.v2GrantService.processGrantUpcomingNotifications, [ScheduledJobType.NEW_GRANTS]: - this.processNewGrantsNotifications.bind(this), + this.v2GrantService.processNewGrantsNotifications, [ScheduledJobType.SAVED_SEARCH_MATCHES]: - this.processSavedSearchMatches.bind(this), + this.v2SavedSearchService.processSavedSearchMatches, [ScheduledJobType.SAVED_SEARCH_MATCHES_NOTIFICATION]: - this.processSavedSearchMatchesNotifications.bind(this), + this.v2SavedSearchService + .processSavedSearchMatchesNotifications, }; const cronFn = CRON_JOB_MAP[type as keyof typeof CRON_JOB_MAP]; const cronJob = getCronJob(cronFn, timer);