mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Refactored verification trigger constructor
refs https://github.com/TryGhost/Toolbox/issues/387 - The constructor should be light initialization logic only. Putting business logic into constructor is quite dirty and not really testable!
This commit is contained in:
parent
456abc3ef2
commit
5934794d86
1 changed files with 19 additions and 16 deletions
|
@ -38,24 +38,27 @@ class VerificationTrigger {
|
|||
this._Settings = Settings;
|
||||
this._eventRepository = eventRepository;
|
||||
|
||||
DomainEvents.subscribe(MemberSubscribeEvent, async (event) => {
|
||||
if (event.data.source === 'api' && isFinite(this._configThreshold)) {
|
||||
const createdAt = new Date();
|
||||
createdAt.setDate(createdAt.getDate() - 30);
|
||||
const events = await this._eventRepository.getNewsletterSubscriptionEvents({}, {
|
||||
'data.source': `data.source:'api'`,
|
||||
'data.created_at': `data.created_at:>'${createdAt.toISOString().replace('T', ' ').substring(0, 19)}'`
|
||||
});
|
||||
this._handleMemberSubscribeEvent = this._handleMemberSubscribeEvent.bind(this);
|
||||
DomainEvents.subscribe(MemberSubscribeEvent, this._handleMemberSubscribeEvent);
|
||||
}
|
||||
|
||||
if (events.meta.pagination.total > this._configThreshold) {
|
||||
await this.startVerificationProcess({
|
||||
amountImported: events.meta.pagination.total,
|
||||
throwOnTrigger: false,
|
||||
source: 'api'
|
||||
});
|
||||
}
|
||||
async _handleMemberSubscribeEvent(event) {
|
||||
if (event.data.source === 'api' && isFinite(this._configThreshold)) {
|
||||
const createdAt = new Date();
|
||||
createdAt.setDate(createdAt.getDate() - 30);
|
||||
const events = await this._eventRepository.getNewsletterSubscriptionEvents({}, {
|
||||
'data.source': `data.source:'api'`,
|
||||
'data.created_at': `data.created_at:>'${createdAt.toISOString().replace('T', ' ').substring(0, 19)}'`
|
||||
});
|
||||
|
||||
if (events.meta.pagination.total > this._configThreshold) {
|
||||
await this.startVerificationProcess({
|
||||
amountImported: events.meta.pagination.total,
|
||||
throwOnTrigger: false,
|
||||
source: 'api'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getImportThreshold() {
|
||||
|
|
Loading…
Reference in a new issue