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.
This commit is contained in:
Naz 2022-08-24 14:23:32 +08:00
parent 966d324e7f
commit 243aa9c834

View File

@ -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
});
}
}