feat: Implement in-app notifications with new database model, enhance Firebase initialization to support service account files, and add message read functionalities.

This commit is contained in:
pradeepkumar
2026-02-25 06:45:27 +05:30
parent 36ccc8c303
commit 7b8d6e3db8
7 changed files with 289 additions and 63 deletions

View File

@@ -1,8 +1,12 @@
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
Query,
UseGuards,
HttpCode,
HttpStatus,
@@ -12,6 +16,7 @@ import {
ApiOperation,
ApiResponse,
ApiBearerAuth,
ApiQuery,
} from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards';
import { CurrentUser } from '../auth/decorators';
@@ -27,6 +32,63 @@ export class NotificationsController {
private readonly notificationsService: NotificationsService,
) {}
// ==========================================
// IN-APP NOTIFICATIONS
// ==========================================
@Get()
@ApiOperation({ summary: 'Get notifications list' })
@ApiQuery({ name: 'filter', required: false, enum: ['all', 'unread'] })
@ApiQuery({ name: 'page', required: false, type: Number })
@ApiQuery({ name: 'limit', required: false, type: Number })
@ApiResponse({ status: 200, description: 'Notifications list with pagination' })
async getNotifications(
@CurrentUser('id') userId: string,
@Query('filter') filter?: 'all' | 'unread',
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
return this.notificationsService.getNotifications(
userId,
filter || 'all',
page ? parseInt(page, 10) : 1,
limit ? parseInt(limit, 10) : 20,
);
}
@Get('unread-count')
@ApiOperation({ summary: 'Get unread notification count' })
@ApiResponse({ status: 200, description: 'Unread count' })
async getUnreadCount(@CurrentUser('id') userId: string) {
const count = await this.notificationsService.getUnreadCount(userId);
return { unreadCount: count };
}
@Patch(':id/read')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Mark a notification as read' })
@ApiResponse({ status: 200, description: 'Notification marked as read' })
async markAsRead(
@CurrentUser('id') userId: string,
@Param('id') notificationId: string,
) {
await this.notificationsService.markAsRead(userId, notificationId);
return null;
}
@Patch('read-all')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Mark all notifications as read' })
@ApiResponse({ status: 200, description: 'All notifications marked as read' })
async markAllAsRead(@CurrentUser('id') userId: string) {
await this.notificationsService.markAllAsRead(userId);
return null;
}
// ==========================================
// FCM TOKEN MANAGEMENT
// ==========================================
@Post('fcm-token')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Register FCM token for push notifications' })