diff --git a/ghost/members-events-service/lib/last-seen-at-updater.js b/ghost/members-events-service/lib/last-seen-at-updater.js index 0231f00145..1100f01ed6 100644 --- a/ghost/members-events-service/lib/last-seen-at-updater.js +++ b/ghost/members-events-service/lib/last-seen-at-updater.js @@ -1,4 +1,3 @@ -const DomainEvents = require('@tryghost/domain-events'); const {MemberPageViewEvent} = require('@tryghost/member-events'); const moment = require('moment-timezone'); @@ -12,6 +11,7 @@ class LastSeenAtUpdater { * @param {Object} deps.models The list of model dependencies * @param {any} deps.models.Member The Member model * @param {Object} deps.services The list of service dependencies + * @param {any} deps.services.domainEvent The DomainEvent service * @param {any} deps.services.settingsCache The settings service */ constructor({ @@ -19,12 +19,15 @@ class LastSeenAtUpdater { Member }, services: { + domainEvent, settingsCache } }) { this._memberModel = Member; + this._domainEventsService = domainEvent; this._settingsCacheService = settingsCache; - DomainEvents.subscribe(MemberPageViewEvent, async (event) => { + + this._domainEventsService.subscribe(MemberPageViewEvent, async (event) => { await this.updateLastSeenAt(event.data.memberId, event.data.memberLastSeenAt, event.timestamp); }); } diff --git a/ghost/members-events-service/test/last-seen-at-updater.test.js b/ghost/members-events-service/test/last-seen-at-updater.test.js index 694ad8ed60..23705c1e75 100644 --- a/ghost/members-events-service/test/last-seen-at-updater.test.js +++ b/ghost/members-events-service/test/last-seen-at-updater.test.js @@ -24,7 +24,8 @@ describe('LastSeenAtUpdater', function () { services: { settingsCache: { get: settingsCache - } + }, + domainEvent: DomainEvents } }); DomainEvents.dispatch(MemberPageViewEvent.create({memberId: '1', memberLastSeenAt: previousLastSeen, url: '/'}, now.toDate())); @@ -49,7 +50,8 @@ describe('LastSeenAtUpdater', function () { services: { settingsCache: { get: settingsCache - } + }, + domainEvent: DomainEvents } }); DomainEvents.dispatch(MemberPageViewEvent.create({memberId: '1', memberLastSeenAt: previousLastSeen, url: '/'}, now.toDate())); @@ -70,7 +72,8 @@ describe('LastSeenAtUpdater', function () { services: { settingsCache: { get: settingsCache - } + }, + domainEvent: DomainEvents } }); DomainEvents.dispatch(MemberPageViewEvent.create({memberId: '1', memberLastSeenAt: previousLastSeen, url: '/'}, now.toDate())); @@ -95,7 +98,8 @@ describe('LastSeenAtUpdater', function () { services: { settingsCache: { get: settingsCache - } + }, + domainEvent: DomainEvents } }); DomainEvents.dispatch(MemberPageViewEvent.create({memberId: '1', memberLastSeenAt: previousLastSeen, url: '/'}, now.toDate())); @@ -115,7 +119,8 @@ describe('LastSeenAtUpdater', function () { services: { settingsCache: { get: settingsCache - } + }, + domainEvent: DomainEvents } }); DomainEvents.dispatch(MemberSubscribeEvent.create({memberId: '1', source: 'api'}, now.toDate()));