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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 9x 9x 9x 9x 9x 2x 3x 1x 4x | import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { NotificationStatus } from '@prisma/client';
import { NotificationDto } from './dto/notification.dto';
@Injectable()
export class NotificationRepository {
constructor(private readonly prisma: PrismaService) {}
async getNotificationsForUser(userId: string): Promise<NotificationDto[]> {
return this.prisma.notification.findMany({
where: {
userId: userId,
status: {
in: ['READ', 'UNREAD'],
},
},
select: {
id: true,
message: true,
status: true,
},
orderBy: {
date: 'desc',
},
});
}
async getNotificationById(id: string) {
return this.prisma.notification.findUnique({
where: {
id: id,
},
});
}
async markNotificationAsRead(userId: string, id: string) {
return this.prisma.notification.update({
where: {
id: id,
userId: userId,
},
data: {
status: NotificationStatus.READ,
},
});
}
async createNotification(userId: string, message: string) {
return this.prisma.notification.create({
data: {
userId: userId,
message: message,
},
});
}
}
|