Files
zod-backend/src/common/modules/notification/dtos/response/notifications.response.dto.ts
Abdalhamid Alhamad 6d6dc1471f feat: add timezone support to user and device entities
- Introduced optional timezone fields in User and Device entities to store user preferences and device timezones.
- Updated request DTOs for login and user updates to include timezone information.
- Enhanced AuthService to handle timezone during device registration and updates.
- Added migration to incorporate timezone fields in the database schema.
2026-01-14 16:12:08 +03:00

40 lines
1.4 KiB
TypeScript

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;
}
}
}