fix(admin-service): 修复通知查询时publishedAt为null的问题
问题:当 publishedAt 为 NULL(表示立即发布)时,Prisma 的
`publishedAt: { lte: now }` 条件不匹配,导致通知无法显示
修复:将查询条件改为 OR 逻辑:
- publishedAt 为 null(立即发布)
- publishedAt <= now(定时发布且已到时间)
影响的方法:
- findNotificationsForUser
- countUnreadForUser
- markAllAsRead
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fea0b42223
commit
e2cf3c3d7e
|
|
@ -146,11 +146,13 @@ export class NotificationRepositoryImpl implements NotificationRepository {
|
||||||
const notifications = await this.prisma.notification.findMany({
|
const notifications = await this.prisma.notification.findMany({
|
||||||
where: {
|
where: {
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
publishedAt: { lte: now },
|
|
||||||
OR: [{ expiresAt: null }, { expiresAt: { gt: now } }],
|
|
||||||
...(params.type && { type: params.type }),
|
...(params.type && { type: params.type }),
|
||||||
// 目标用户筛选
|
|
||||||
AND: [
|
AND: [
|
||||||
|
// publishedAt 为 null 表示立即发布,或者 publishedAt <= now
|
||||||
|
{ OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] },
|
||||||
|
// expiresAt 为 null 表示永不过期,或者 expiresAt > now
|
||||||
|
{ OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] },
|
||||||
|
// 目标用户筛选
|
||||||
{
|
{
|
||||||
OR: [
|
OR: [
|
||||||
// ALL: 发给所有人
|
// ALL: 发给所有人
|
||||||
|
|
@ -204,13 +206,15 @@ export class NotificationRepositoryImpl implements NotificationRepository {
|
||||||
const count = await this.prisma.notification.count({
|
const count = await this.prisma.notification.count({
|
||||||
where: {
|
where: {
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
publishedAt: { lte: now },
|
|
||||||
OR: [{ expiresAt: null }, { expiresAt: { gt: now } }],
|
|
||||||
readRecords: {
|
readRecords: {
|
||||||
none: { userSerialNum },
|
none: { userSerialNum },
|
||||||
},
|
},
|
||||||
// 目标用户筛选
|
|
||||||
AND: [
|
AND: [
|
||||||
|
// publishedAt 为 null 表示立即发布,或者 publishedAt <= now
|
||||||
|
{ OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] },
|
||||||
|
// expiresAt 为 null 表示永不过期,或者 expiresAt > now
|
||||||
|
{ OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] },
|
||||||
|
// 目标用户筛选
|
||||||
{
|
{
|
||||||
OR: [
|
OR: [
|
||||||
{ targetType: 'ALL' },
|
{ targetType: 'ALL' },
|
||||||
|
|
@ -265,12 +269,15 @@ export class NotificationRepositoryImpl implements NotificationRepository {
|
||||||
const unreadNotifications = await this.prisma.notification.findMany({
|
const unreadNotifications = await this.prisma.notification.findMany({
|
||||||
where: {
|
where: {
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
publishedAt: { lte: now },
|
|
||||||
OR: [{ expiresAt: null }, { expiresAt: { gt: now } }],
|
|
||||||
readRecords: {
|
readRecords: {
|
||||||
none: { userSerialNum },
|
none: { userSerialNum },
|
||||||
},
|
},
|
||||||
AND: [
|
AND: [
|
||||||
|
// publishedAt 为 null 表示立即发布,或者 publishedAt <= now
|
||||||
|
{ OR: [{ publishedAt: null }, { publishedAt: { lte: now } }] },
|
||||||
|
// expiresAt 为 null 表示永不过期,或者 expiresAt > now
|
||||||
|
{ OR: [{ expiresAt: null }, { expiresAt: { gt: now } }] },
|
||||||
|
// 目标用户筛选
|
||||||
{
|
{
|
||||||
OR: [
|
OR: [
|
||||||
{ targetType: 'ALL' },
|
{ targetType: 'ALL' },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue