read notif

This commit is contained in:
2025-12-15 09:21:55 +03:30
parent 996cd0016c
commit 6bcfda19c9
2 changed files with 37 additions and 10 deletions
@@ -119,12 +119,29 @@ export class NotificationService {
);
}
async removeNotification(id: string, restaurantId: string): Promise<void> {
const notification = await this.em.findOne(Notification, { id, restaurant: { id: restaurantId } });
async readNotificationAdmin(id: string, adminId: string, restaurantId: string): Promise<void> {
const notification = await this.em.findOne(Notification, {
id,
admin: { id: adminId },
restaurant: { id: restaurantId },
});
if (!notification) {
throw new NotFoundException('Notification not found');
}
await this.em.removeAndFlush(notification as any);
notification.sentAt = new Date();
await this.em.persistAndFlush(notification);
}
async readNotificationAsUser(id: string, userId: string, restaurantId: string): Promise<void> {
const notification = await this.em.findOne(Notification, {
id,
user: { id: userId },
restaurant: { id: restaurantId },
});
if (!notification) {
throw new NotFoundException('Notification not found');
}
notification.sentAt = new Date();
await this.em.persistAndFlush(notification);
}
async findByRestaurantAndType(restaurantId: string, title: NotifTitleEnum, limit = 50): Promise<Notification[]> {