All files / src/domain/notification notification.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                                                                          26x 26x 26x 26x 26x 26x 26x 26x 26x       20x                           6x       3x                          
export type NotificationType = 'VACCINE_DELAYED' | 'APPOINTMENT_UPCOMING';
 
export interface NotificationProps {
  id: string;
  userId: string;
  babyId: string;
  type: NotificationType;
  referenceId: string;
  title: string;
  message: string;
  readAt: Date | null;
  createdAt: Date;
}
 
export interface CreateNotificationProps {
  id: string;
  userId: string;
  babyId: string;
  type: NotificationType;
  referenceId: string;
  title: string;
  message: string;
  createdAt?: Date;
}
 
export class Notification {
  readonly id: string;
  readonly userId: string;
  readonly babyId: string;
  readonly type: NotificationType;
  readonly referenceId: string;
  readonly title: string;
  readonly message: string;
  readonly readAt: Date | null;
  readonly createdAt: Date;
 
  private constructor(props: NotificationProps) {
    this.id = props.id;
    this.userId = props.userId;
    this.babyId = props.babyId;
    this.type = props.type;
    this.referenceId = props.referenceId;
    this.title = props.title;
    this.message = props.message;
    this.readAt = props.readAt;
    this.createdAt = props.createdAt;
  }
 
  static create(props: CreateNotificationProps): Notification {
    return new Notification({
      id: props.id,
      userId: props.userId,
      babyId: props.babyId,
      type: props.type,
      referenceId: props.referenceId,
      title: props.title,
      message: props.message,
      readAt: null,
      createdAt: props.createdAt ?? new Date(),
    });
  }
 
  static restore(props: NotificationProps): Notification {
    return new Notification(props);
  }
 
  markAsRead(): Notification {
    return Notification.restore({
      id: this.id,
      userId: this.userId,
      babyId: this.babyId,
      type: this.type,
      referenceId: this.referenceId,
      title: this.title,
      message: this.message,
      readAt: new Date(),
      createdAt: this.createdAt,
    });
  }
}