Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 9x 9x 9x 9x 2x 3x 3x 1x 2x 1x 1x | import {
ForbiddenException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { NotificationRepository } from './notification.repository';
import { NotificationDto } from './dto/notification.dto';
@Injectable()
export class NotificationService {
constructor(
private readonly notificationRepository: NotificationRepository,
) {}
async getNotificationsForUser(userId: string): Promise<NotificationDto[]> {
return this.notificationRepository.getNotificationsForUser(userId);
}
async markNotificationAsRead(userId: string, id: string) {
const result = await this.notificationRepository.getNotificationById(id);
if (!result) {
throw new NotFoundException('Notification not found');
} else if (result.userId !== userId) {
throw new ForbiddenException('Notification does not belong to user');
}
await this.notificationRepository.markNotificationAsRead(userId, id);
}
}
|