1- import { Controller , Get , Param , Query , Request } from '@nestjs/common' ;
2- import { ApiBearerAuth , ApiQuery , ApiResponse } from '@nestjs/swagger' ;
1+ import {
2+ Controller ,
3+ Delete ,
4+ Get ,
5+ Param ,
6+ Patch ,
7+ Query ,
8+ Request ,
9+ UseGuards ,
10+ } from '@nestjs/common' ;
11+ import {
12+ ApiBearerAuth ,
13+ ApiOperation ,
14+ ApiParam ,
15+ ApiQuery ,
16+ ApiResponse ,
17+ } from '@nestjs/swagger' ;
18+ import { JwtAdminsGuard } from 'src/shared/auth/guards/jwt.admins.guard' ;
19+ import { JwtUsersGuard } from 'src/shared/auth/guards/jwt.users.guard' ;
320import { ApiReq } from 'src/shared/interfaces' ;
421import { NotificationsService } from './notifications.service' ;
522
@@ -8,20 +25,27 @@ import { NotificationsService } from './notifications.service';
825export class NotificationsController {
926 constructor ( private readonly notificationsService : NotificationsService ) { }
1027
11- @Get ( '/notifications' )
28+ @ApiBearerAuth ( )
29+ @ApiOperation ( {
30+ summary : 'get all notifications' ,
31+ description :
32+ 'returns all notifications based on the user type making the request' ,
33+ } )
1234 @ApiResponse ( {
1335 status : 200 ,
1436 description : 'List of notifications' ,
1537 } )
38+ @UseGuards ( JwtUsersGuard )
39+ @Get ( )
1640 async getNotifications ( @Request ( ) req : ApiReq ) : Promise < string [ ] > {
17- // fetch notifications for user
1841 const notifications = await this . notificationsService . getNotifications (
1942 req . user . _id . toString ( ) ,
2043 ) ;
2144 return notifications ;
2245 }
2346
24- @Get ( '/notifications/:notificationId' )
47+ @UseGuards ( JwtUsersGuard )
48+ @Get ( ':notificationId' )
2549 @ApiResponse ( {
2650 status : 200 ,
2751 description : 'Return the id of the object that prompted the notification' ,
@@ -33,4 +57,83 @@ export class NotificationsController {
3357 await this . notificationsService . getNotificationById ( notificationId ) ;
3458 return notification ;
3559 }
60+
61+ @ApiBearerAuth ( )
62+ @ApiOperation ( {
63+ summary :
64+ 'Mark notification as read for users (DOES NOT WORK FOR ADMIN NOTIFICATIONS)' ,
65+ description :
66+ 'Marks a specific notification as read for the requesting user' ,
67+ } )
68+ @ApiParam ( { name : 'notificationId' , type : 'string' } )
69+ @ApiResponse ( {
70+ status : 200 ,
71+ description : 'Notification marked as read' ,
72+ } )
73+ @UseGuards ( JwtUsersGuard )
74+ @Patch ( ':notificationId/read' )
75+ async markNotificationAsRead (
76+ @Param ( 'notificationId' ) notificationId : string ,
77+ @Request ( ) req : ApiReq ,
78+ ) : Promise < boolean > {
79+ return await this . notificationsService . userReadNotification (
80+ notificationId ,
81+ req . user . _id . toString ( ) ,
82+ ) ;
83+ }
84+
85+ @ApiBearerAuth ( )
86+ @ApiOperation ( {
87+ summary : 'Clear all notifications for user' ,
88+ description : 'Deletes all notifications for the requesting user' ,
89+ } )
90+ @ApiResponse ( {
91+ status : 200 ,
92+ description : 'Notifications cleared' ,
93+ } )
94+ @UseGuards ( JwtUsersGuard )
95+ @Delete ( 'clear' )
96+ async clearUserNotifications ( @Request ( ) req : ApiReq ) : Promise < boolean > {
97+ return await this . notificationsService . userClearNotifications (
98+ req . user . _id . toString ( ) ,
99+ ) ;
100+ }
101+
102+ @ApiBearerAuth ( )
103+ @ApiOperation ( {
104+ summary : 'Get admin notifications dashboard' ,
105+ description : 'Returns all admin notifications with optional filtering' ,
106+ } )
107+ @ApiQuery ( { name : 'status' , required : false , enum : [ 'pending' , 'read' ] } )
108+ @ApiResponse ( {
109+ status : 200 ,
110+ description : 'List of admin notifications' ,
111+ } )
112+ @UseGuards ( JwtAdminsGuard )
113+ @Get ( 'admin/dashboard' )
114+ async getAdminNotifications (
115+ @Query ( 'status' ) status ?: string ,
116+ ) : Promise < any [ ] > {
117+ return await this . notificationsService . getAdminNotifications ( status ) ;
118+ }
119+
120+ @ApiBearerAuth ( )
121+ @ApiOperation ( {
122+ summary : 'Mark admin notification as read' ,
123+ description : 'Marks a specific notification as read for admins' ,
124+ } )
125+ @ApiParam ( { name : 'notificationId' , type : 'string' } )
126+ @ApiResponse ( {
127+ status : 200 ,
128+ description : 'Notification marked as read' ,
129+ } )
130+ @UseGuards ( JwtAdminsGuard )
131+ @Patch ( 'admin/:notificationId/read' )
132+ async markAdminNotificationAsRead (
133+ @Param ( 'notificationId' ) notificationId : string ,
134+ ) : Promise < boolean > {
135+ return await this . notificationsService . adminReadNotification (
136+ notificationId ,
137+ ) ;
138+ }
36139}
0 commit comments