/
PostmenBlake
/
NotificationPreferencesService
Обзор
Документация
Войти
/
PostmenBlake
/
NotificationPreferencesService
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/domain/entities/UserPreference.ts
74 строки
2 KB
kurava
feat: initial commit - Notification Preferences Service
17 июн 2026, 09:11
17 июн 2026, 09:11
48825c3
Код
Авторство
О чём код?
import { NotificationType } from '../value-objects/NotificationType'; import { QuietHours, isValidQuietHours } from '../value-objects/QuietHours'; export interface UserPreferenceProps { userId: string; preferences: Record<NotificationType, boolean>; quietHours?: QuietHours | null; region: string; createdAt: Date; updatedAt: Date; } export class UserPreference { public readonly userId: string; public preferences: Record<NotificationType, boolean>; public quietHours?: QuietHours | null; public readonly region: string; public readonly createdAt: Date; public updatedAt: Date; constructor(props: UserPreferenceProps) { this.userId = props.userId; this.preferences = props.preferences; this.quietHours = props.quietHours; this.region = props.region; this.createdAt = props.createdAt; this.updatedAt = props.updatedAt; } public updatePreference( notificationType: NotificationType, enabled: boolean, ): void { this.preferences[notificationType] = enabled; this.updatedAt = new Date(); } public updateQuietHours(quietHours: QuietHours | null): void { if (quietHours && !isValidQuietHours(quietHours)) { throw new Error('Invalid quiet hours configuration'); } this.quietHours = quietHours; this.updatedAt = new Date(); } public isNotificationEnabled( notificationType: NotificationType, datetime: Date, ): boolean { // Check if the notification type is enabled in user preferences if (!this.preferences[notificationType]) { return false; } // Check quiet hours if (this.quietHours) { const notificationTypeObj = notificationType as NotificationType; // Marketing notifications are blocked during quiet hours if ( (notificationTypeObj === NotificationType.MARKETING_EMAIL || notificationTypeObj === NotificationType.MARKETING_PUSH || notificationTypeObj === NotificationType.MARKETING_SMS) && isWithinQuietHours(this.quietHours, datetime) ) { return false; } } return true; } } // Re-export for convenience import { isWithinQuietHours } from '../value-objects/QuietHours';