import { QueueSSEService } from '../queue/queue-sse.service' ; import { Connection , EntitySubscriberInterface , EventSubscriber , UpdateEvent , } from 'typeorm' ; import { QueueModel } from './queue.entity' ; @ EventSubscriber ( ) export class QueueSubscriber implements EntitySubscriberInterface < QueueModel > { private queueSSEService : QueueSSEService ; constructor ( connection , queueSSEService ) { this . queueSSEService = queueSSEService ; connection . subscribers . push ( this ) ; } listenTo ( ) { return QueueModel ; } async afterUpdate ( event ) { if ( event . entity ) { await this . queueSSEService . updateQueue ( event . entity . id ) ; } } }