20 lines
786 B
TypeScript
Executable File
20 lines
786 B
TypeScript
Executable File
import { EntityRepository } from "@mikro-orm/postgresql";
|
|
|
|
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
|
import { SearchNotificationQueryDto } from "../DTO/search-notification-query.dto";
|
|
import { Notification } from "../entities/notification.entity";
|
|
|
|
export class NotificationRepository extends EntityRepository<Notification> {
|
|
async getAllNotifications(queryDto: SearchNotificationQueryDto, recipientId: string) {
|
|
const { skip, limit } = PaginationUtils(queryDto);
|
|
|
|
const qb = this.qb("notification").where({ recipient: { id: recipientId } });
|
|
|
|
if (queryDto.isRead !== undefined) {
|
|
qb.andWhere({ isRead: queryDto.isRead === 1 });
|
|
}
|
|
|
|
return qb.orderBy({ createdAt: "DESC" }).offset(skip).limit(limit).getResultAndCount();
|
|
}
|
|
}
|