diff --git a/src/modules/notifications/controllers/notifications.controller.ts b/src/modules/notifications/controllers/notifications.controller.ts index 6d3eda8..c396bac 100644 --- a/src/modules/notifications/controllers/notifications.controller.ts +++ b/src/modules/notifications/controllers/notifications.controller.ts @@ -67,6 +67,14 @@ export class NotificationsController { return { message: 'Notification read successfully' }; } + @UseGuards(AuthGuard) + @ApiBearerAuth() + @Put('public/notifications/read/all') + @ApiOperation({ summary: 'Read all notification ' }) + async readAllNotificationUser(@RestId() restaurantId: string, @UserId() userId: string) { + await this.notificationService.readAllNotifsAsUser(userId, restaurantId); + return { message: 'Notification read successfully' }; + } /* ***************** Admin Endpoints ***************** */ @UseGuards(AdminAuthGuard) @@ -111,6 +119,15 @@ export class NotificationsController { return { message: 'Notification read successfully' }; } + @UseGuards(AdminAuthGuard) + @ApiBearerAuth() + @Put('admin/notifications/read/all') + @ApiOperation({ summary: 'Read all notification ' }) + async readAllNotificationAdmin(@RestId() restaurantId: string, @AdminId() adminId: string, @Param('id') id: string) { + await this.notificationService.readAllNotifsAsAdmin(adminId, restaurantId); + return { message: 'Notification read successfully' }; + } + @UseGuards(AdminAuthGuard) @ApiBearerAuth() @Get('admin/notification-preferences') diff --git a/src/modules/notifications/services/notification.service.ts b/src/modules/notifications/services/notification.service.ts index 527ca87..66993c1 100644 --- a/src/modules/notifications/services/notification.service.ts +++ b/src/modules/notifications/services/notification.service.ts @@ -244,4 +244,22 @@ export class NotificationService { }; return this.em.count(Notification, where); } + + readAllNotifsAsUser(userId: string, restaurantId: string): Promise { + const where: FilterQuery = { + user: { id: userId }, + restaurant: { id: restaurantId }, + seenAt: null, + }; + return this.em.nativeUpdate(Notification, where, { seenAt: new Date() }); + } + + readAllNotifsAsAdmin(adminId: string, restaurantId: string): Promise { + const where: FilterQuery = { + admin: { id: adminId }, + restaurant: { id: restaurantId }, + seenAt: null, + }; + return this.em.nativeUpdate(Notification, where, { seenAt: new Date() }); + } }