107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
import {
|
||
NotificationEntity,
|
||
NotificationType,
|
||
NotificationPriority,
|
||
TargetType,
|
||
NotificationTarget,
|
||
} from '../../../domain/entities/notification.entity';
|
||
import { NotificationWithReadStatus } from '../../../domain/repositories/notification.repository';
|
||
|
||
/**
|
||
* 目标配置响应
|
||
*/
|
||
export interface TargetConfigResponseDto {
|
||
type: TargetType;
|
||
tagIds?: string[];
|
||
segmentId?: string;
|
||
accountSequences?: string[];
|
||
}
|
||
|
||
/**
|
||
* 通知响应DTO
|
||
*/
|
||
export class NotificationResponseDto {
|
||
id: string;
|
||
title: string;
|
||
content: string;
|
||
type: NotificationType;
|
||
priority: NotificationPriority;
|
||
targetType: TargetType;
|
||
targetConfig: TargetConfigResponseDto | null;
|
||
imageUrl: string | null;
|
||
linkUrl: string | null;
|
||
isEnabled: boolean;
|
||
requiresForceRead: boolean;
|
||
publishedAt: string | null;
|
||
expiresAt: string | null;
|
||
createdAt: string;
|
||
|
||
static fromEntity(entity: NotificationEntity): NotificationResponseDto {
|
||
return {
|
||
id: entity.id,
|
||
title: entity.title,
|
||
content: entity.content,
|
||
type: entity.type,
|
||
priority: entity.priority,
|
||
targetType: entity.targetType,
|
||
targetConfig: entity.targetConfig,
|
||
imageUrl: entity.imageUrl,
|
||
linkUrl: entity.linkUrl,
|
||
isEnabled: entity.isEnabled,
|
||
requiresForceRead: entity.requiresForceRead,
|
||
publishedAt: entity.publishedAt?.toISOString() ?? null,
|
||
expiresAt: entity.expiresAt?.toISOString() ?? null,
|
||
createdAt: entity.createdAt.toISOString(),
|
||
};
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 带已读状态的通知响应DTO(用于用户端)
|
||
*/
|
||
export class UserNotificationResponseDto {
|
||
id: string;
|
||
title: string;
|
||
content: string;
|
||
type: NotificationType;
|
||
priority: NotificationPriority;
|
||
imageUrl: string | null;
|
||
linkUrl: string | null;
|
||
publishedAt: string | null;
|
||
isRead: boolean;
|
||
readAt: string | null;
|
||
requiresForceRead: boolean;
|
||
|
||
static fromEntity(item: NotificationWithReadStatus): UserNotificationResponseDto {
|
||
return {
|
||
id: item.notification.id,
|
||
title: item.notification.title,
|
||
content: item.notification.content,
|
||
type: item.notification.type,
|
||
priority: item.notification.priority,
|
||
imageUrl: item.notification.imageUrl,
|
||
linkUrl: item.notification.linkUrl,
|
||
publishedAt: item.notification.publishedAt?.toISOString() ?? null,
|
||
isRead: item.isRead,
|
||
readAt: item.readAt?.toISOString() ?? null,
|
||
requiresForceRead: item.notification.requiresForceRead,
|
||
};
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 未读数量响应
|
||
*/
|
||
export class UnreadCountResponseDto {
|
||
unreadCount: number;
|
||
}
|
||
|
||
/**
|
||
* 通知列表响应
|
||
*/
|
||
export class NotificationListResponseDto {
|
||
notifications: UserNotificationResponseDto[];
|
||
total: number;
|
||
unreadCount: number;
|
||
}
|