From 243aa9c834028f871806e218014e2425f0fb7995 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 24 Aug 2022 14:23:32 +0800 Subject: [PATCH] Refactored member subscribe handler generic refs https://github.com/TryGhost/Toolbox/issues/387 - I'm about to add another event source - "admin". Before doing that made the method more parameter dependent, so it can handle limit triggering logic from multiple source and based on multiple configuration parameters. --- .../verification-trigger/lib/verification-trigger.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ghost/verification-trigger/lib/verification-trigger.js b/ghost/verification-trigger/lib/verification-trigger.js index 0f03026b99..6e693488bc 100644 --- a/ghost/verification-trigger/lib/verification-trigger.js +++ b/ghost/verification-trigger/lib/verification-trigger.js @@ -43,19 +43,22 @@ class VerificationTrigger { } async _handleMemberSubscribeEvent(event) { - if (event.data.source === 'api' && isFinite(this._configThreshold)) { + const source = event.data?.source; + const sourceThreshold = this._configThreshold; + + if (source === 'api' && isFinite(sourceThreshold)) { const createdAt = new Date(); createdAt.setDate(createdAt.getDate() - 30); const events = await this._eventRepository.getNewsletterSubscriptionEvents({}, { - 'data.source': `data.source:'api'`, + 'data.source': `data.source:'${source}'`, 'data.created_at': `data.created_at:>'${createdAt.toISOString().replace('T', ' ').substring(0, 19)}'` }); - if (events.meta.pagination.total > this._configThreshold) { + if (events.meta.pagination.total > sourceThreshold) { await this.startVerificationProcess({ amountImported: events.meta.pagination.total, throwOnTrigger: false, - source: 'api' + source: source }); } }