import { ApiProperty } from '@nestjs/swagger'; import { Notification } from '../../entities'; import { NotificationStatus } from '../../enums'; export class NotificationsResponseDto { @ApiProperty({ example: 'f1b1b9b1-1b1b-1b1b-1b1b-1b1b1b1b1b1b' }) id!: string; @ApiProperty({ example: 'Test' }) title: string; @ApiProperty({ example: 'TestBody' }) body: string; @ApiProperty({ example: NotificationStatus.UNREAD }) status!: NotificationStatus; @ApiProperty({ example: '2021-09-01T00:00:00.000Z' }) createdAt!: Date; constructor(notification: Notification) { this.id = notification.id; this.title = notification.title; this.body = notification.message; this.status = notification.status!; // Use event timestamp from data if available, otherwise use notification creation time // This ensures notifications show when the event occurred, not when notification was saved // Note: Timestamps are stored in UTC. The client should convert to the user's local timezone. if (notification.data?.timestamp) { // Parse the ISO string timestamp (which is in UTC) // The client should convert this to the user's local timezone based on their device settings this.createdAt = new Date(notification.data.timestamp); } else { // Use notification creation time (also in UTC) this.createdAt = notification.createdAt; } } }