import { Inject , Injectable } from '@nestjs/common' ; import { EventBus } from '@nestjs/cqrs' ; import { LoggerService } from '@fc/logger' ; import { APP_TRACKING_SERVICE } from './app-tracking-service.token' ; import { IAppTrackingService , IEvent , IEventContext , IEventMap , } from './interfaces' ; @ Injectable ( ) export class TrackingService { constructor ( @ Inject ( APP_TRACKING_SERVICE ) private readonly appTrackingService , private readonly eventBus , private readonly logger ) { } get EventsMap ( ) : IEventMap { return this . appTrackingService . EventsMap ; } track ( EventClass , context ) { const event = new EventClass ( context ) ; this . eventBus . publish ( event ) ; } async log ( event , context ) { const message = await this . appTrackingService . buildLog ( event , context ) ; this . logger . businessEvent ( message ) ; } }