29 lines
951 B
TypeScript
29 lines
951 B
TypeScript
import { Injectable } from '@nestjs/common';
|
||
import { Observable, Subject } from 'rxjs';
|
||
import { CommentDto } from '../dto/comment.dto.js';
|
||
|
||
export type CommentEventType = 'comment.created' | 'comment.updated' | 'comment.deleted';
|
||
|
||
export interface CommentEvent {
|
||
type: CommentEventType;
|
||
comment: CommentDto;
|
||
}
|
||
|
||
/**
|
||
* In-process шина событий comment-модуля для SSE-подписчиков
|
||
* (по аналогии с IssueEventsService). Работает в пределах одного
|
||
* инстанса приложения — для нескольких инстансов понадобится Redis pub/sub.
|
||
*/
|
||
@Injectable()
|
||
export class CommentEventsService {
|
||
private readonly events$ = new Subject<CommentEvent>();
|
||
|
||
emit(type: CommentEventType, comment: CommentDto): void {
|
||
this.events$.next({ type, comment });
|
||
}
|
||
|
||
onEvents(): Observable<CommentEvent> {
|
||
return this.events$.asObservable();
|
||
}
|
||
}
|