21 lines
770 B
TypeScript
21 lines
770 B
TypeScript
import { Controller, Get, Req, Sse,
|
|
MessageEvent as NestMessageEvent } from "@nestjs/common";
|
|
import { Observable } from "rxjs";
|
|
import { map } from 'rxjs/operators';
|
|
import { NotificationsService } from "src/shared/notifications/notifications.service";
|
|
|
|
@Controller('notifications')
|
|
export class NotificationsController {
|
|
constructor(private readonly notificationsService: NotificationsService) {}
|
|
|
|
@Get('summary')
|
|
async summary(@Req() req) {
|
|
return this.notificationsService.summary(String(req.user.id));
|
|
}
|
|
|
|
@Sse('stream')
|
|
stream(@Req() req): Observable<NestMessageEvent> {
|
|
const userId = String(req.user.id);
|
|
return this.notificationsService.stream(userId).pipe(map((data): NestMessageEvent => ({ data })))
|
|
}
|
|
} |