chore: mark all as read in notifications
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
|
||||
import { PaginationDto } from "../../../common/DTO/pagination.dto";
|
||||
import { NotificationMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { CommonMessage, NotificationMessage, UserMessage } from "../../../common/enums/message.enum";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { CreateNotificationDto } from "../DTO/create-notification.dto";
|
||||
import { SearchNotificationQueryDto } from "../DTO/search-notification-query.dto";
|
||||
import { NotificationRepository } from "../repositories/notifications.repository";
|
||||
|
||||
@Injectable()
|
||||
@@ -44,22 +43,39 @@ export class NotificationsService {
|
||||
//************************ */
|
||||
|
||||
async createLoginNotification(recipientId: string) {
|
||||
const message = NotificationMessage.LOGIN_MESSAGE.replace("[DATE]", new Date().toLocaleString("fa-IR"));
|
||||
const message = NotificationMessage.LOGIN_MESSAGE;
|
||||
return this.createNotification({ title: NotificationMessage.LOGIN, message, recipientId });
|
||||
}
|
||||
|
||||
//************************ */
|
||||
|
||||
async getAllNotifications(paginationDto: PaginationDto, recipientId: string) {
|
||||
const { skip, limit } = PaginationUtils(paginationDto);
|
||||
const [notifications, count] = await this.notificationRepository
|
||||
.createQueryBuilder("notification")
|
||||
.where("notification.recipientId = :recipientId", { recipientId })
|
||||
.orderBy("notification.createdAt", "DESC")
|
||||
.skip(skip)
|
||||
.take(limit)
|
||||
.getManyAndCount();
|
||||
async getAllNotifications(queryDto: SearchNotificationQueryDto, recipientId: string) {
|
||||
return await this.notificationRepository.getAllNotifications(queryDto, recipientId);
|
||||
}
|
||||
|
||||
return { notifications, count, paginate: true };
|
||||
//************************ */
|
||||
|
||||
async getOneNotification(id: string) {
|
||||
const notification = await this.notificationRepository.findOneBy({ id });
|
||||
if (!notification) throw new BadRequestException(NotificationMessage.NOTIFICATION_NOT_FOUND_OR_ACCESS_DENIED);
|
||||
return { notification };
|
||||
}
|
||||
|
||||
//************************ */
|
||||
|
||||
async markAllAsRead(userId: string) {
|
||||
await this.notificationRepository.update(
|
||||
{
|
||||
recipient: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
{
|
||||
isRead: true,
|
||||
},
|
||||
);
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user