import { Transform, Type } from 'class-transformer' import { isNil } from 'lodash' import { parseDate, parseISO } from '../utils/date' import { NotificationType } from './enums/notification_type.enum' import { Patient } from './patient.model' import { User } from './user.model' export class Notification { id: string user_id: string type: NotificationType title: string message: string patient_id: string resource_id: string @Transform(value => parseDate(value), { toClassOnly: true }) created_at: Date @Transform(value => parseISO(value), { toClassOnly: true }) read_at: Date @Type(() => User) user?: User @Type(() => Patient) patient?: Patient get isUnread(): boolean { return isNil(this.read_at) } constructor(args: Partial) { Object.assign(this, args) } }