see all notifs

This commit is contained in:
2025-12-21 15:13:11 +03:30
parent a605e2a5e6
commit 2f409e5c8c
2 changed files with 35 additions and 0 deletions
@@ -67,6 +67,14 @@ export class NotificationsController {
return { message: 'Notification read successfully' }; 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 ***************** */ /* ***************** Admin Endpoints ***************** */
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@@ -111,6 +119,15 @@ export class NotificationsController {
return { message: 'Notification read successfully' }; 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) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@Get('admin/notification-preferences') @Get('admin/notification-preferences')
@@ -244,4 +244,22 @@ export class NotificationService {
}; };
return this.em.count(Notification, where); return this.em.count(Notification, where);
} }
readAllNotifsAsUser(userId: string, restaurantId: string): Promise<number> {
const where: FilterQuery<Notification> = {
user: { id: userId },
restaurant: { id: restaurantId },
seenAt: null,
};
return this.em.nativeUpdate(Notification, where, { seenAt: new Date() });
}
readAllNotifsAsAdmin(adminId: string, restaurantId: string): Promise<number> {
const where: FilterQuery<Notification> = {
admin: { id: adminId },
restaurant: { id: restaurantId },
seenAt: null,
};
return this.em.nativeUpdate(Notification, where, { seenAt: new Date() });
}
} }