import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository, EntityManager } from 'typeorm'; import { NotificationData } from '../entity/notification.entity'; @Injectable() export class NotificationRepository { constructor( @InjectRepository(NotificationData) private readonly notificationRepo: Repository, ) {} async getAllNotifications( userId: number, levelId: number, levelType: string, isReadFilter?, ) { const qb = this.notificationRepo .createQueryBuilder('n') .where('n.user_id = :userId', { userId }) .andWhere('n.level_id = :levelId', { levelId }) .andWhere('n.level_type = :levelType', { levelType }); if (isReadFilter !== undefined) { qb.andWhere('n.is_read = :isRead', { isRead: isReadFilter }); } qb.orderBy('n.created_date', 'DESC'); return await qb.getMany(); } }