mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
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:
parent
966d324e7f
commit
243aa9c834
@ -43,19 +43,22 @@ class VerificationTrigger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handleMemberSubscribeEvent(event) {
|
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();
|
const createdAt = new Date();
|
||||||
createdAt.setDate(createdAt.getDate() - 30);
|
createdAt.setDate(createdAt.getDate() - 30);
|
||||||
const events = await this._eventRepository.getNewsletterSubscriptionEvents({}, {
|
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)}'`
|
'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({
|
await this.startVerificationProcess({
|
||||||
amountImported: events.meta.pagination.total,
|
amountImported: events.meta.pagination.total,
|
||||||
throwOnTrigger: false,
|
throwOnTrigger: false,
|
||||||
source: 'api'
|
source: source
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user