2026-05-17 00:39:46 +08:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
2026-05-09 18:25:04 +08:00
|
|
|
|
|
|
|
|
@Injectable()
|
2026-05-17 00:39:46 +08:00
|
|
|
export class NotificationsRepository {
|
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
2026-05-09 18:25:04 +08:00
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async findAll(userId: string) {
|
|
|
|
|
return this.prisma.notification.findMany({
|
|
|
|
|
where: { userId },
|
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async create(data: { userId: string; type: string; title: string; body: string }) {
|
|
|
|
|
return this.prisma.notification.create({
|
|
|
|
|
data: {
|
|
|
|
|
userId: data.userId,
|
|
|
|
|
type: data.type,
|
|
|
|
|
title: data.title,
|
|
|
|
|
content: data.body,
|
|
|
|
|
},
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async findById(id: string) {
|
|
|
|
|
return this.prisma.notification.findUnique({ where: { id } });
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-17 00:39:46 +08:00
|
|
|
async markRead(id: string) {
|
|
|
|
|
return this.prisma.notification.update({
|
|
|
|
|
where: { id },
|
|
|
|
|
data: { readAt: new Date() },
|
|
|
|
|
});
|
2026-05-09 18:25:04 +08:00
|
|
|
}
|
|
|
|
|
}
|