import { Connection , EntitySubscriberInterface , EventSubscriber , InsertEvent , UpdateEvent } from 'typeorm' ; import { Notification } from '../entity/notification.entity' ; import { InjectConnection } from '@nestjs/typeorm' ; import { PusherService } from '../service/pusher.service' ; @ EventSubscriber ( ) export class NotificationSubscriber implements EntitySubscriberInterface < Notification > { constructor ( @ InjectConnection ( ) readonly connection , private readonly pusherService ) { connection . subscribers . push ( this ) ; } listenTo ( ) { return Notification ; } async afterInsert ( event ) { this . pusherService . postMessageToUser ( event . entity ) ; } async afterUpdate ( event ) { this . pusherService . postMessageToUser ( event . entity ) ; } }