import { Body, Controller, Get, Post, Query, Req, UseGuards, } from '@nestjs/common'; import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard'; import { NotificationsService } from '../service/notification.service'; @Controller('notifications') export class NotificationsController { constructor(private readonly notificationsService: NotificationsService) {} // Store token from frontend @Post('register-token') async registerToken(@Body() body: { userId?: string; token: string }) { // Optional: associate token with userId if provided return this.notificationsService.saveToken(body.userId, body.token); } @Post('send') async sendNotification( @Body() body: { token: string; title: string; message: string; data?: Record; }, ) { return this.notificationsService.sendToDevice( body.token, body.title, body.message, body.data, ); } @Get('all') @UseGuards(JwtAuthGuard) async getNotifications(@Req() req: any, @Query() filterQuery: any) { const loggedInUser = req.user.userData; return this.notificationsService.getAllNotifications( loggedInUser, filterQuery, ); } @Post('mark-all-read') @UseGuards(JwtAuthGuard) async markAllAsRead(@Req() req: any) { const loggedInUser = req.user.userData; return this.notificationsService.markAllAsRead(loggedInUser); } }