All files / src/domain/baby baby-guardian.ts

100% Statements 8/8
75% Branches 3/4
100% Functions 4/4
100% Lines 8/8

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                                                    550x 550x 550x 550x 550x       211x                   339x       8x      
export type GuardianRole = 'OWNER' | 'GUARDIAN';
 
export interface BabyGuardianProps {
  id: string;
  babyId: string;
  userId: string;
  role: GuardianRole;
  createdAt: Date;
}
 
export interface CreateBabyGuardianProps {
  id: string;
  babyId: string;
  userId: string;
  role?: GuardianRole;
  createdAt?: Date;
}
 
export class BabyGuardian {
  readonly id: string;
  readonly babyId: string;
  readonly userId: string;
  readonly role: GuardianRole;
  readonly createdAt: Date;
 
  private constructor(props: BabyGuardianProps) {
    this.id = props.id;
    this.babyId = props.babyId;
    this.userId = props.userId;
    this.role = props.role;
    this.createdAt = props.createdAt;
  }
 
  static create(props: CreateBabyGuardianProps): BabyGuardian {
    return new BabyGuardian({
      id: props.id,
      babyId: props.babyId,
      userId: props.userId,
      role: props.role ?? 'GUARDIAN',
      createdAt: props.createdAt ?? new Date(),
    });
  }
 
  static restore(props: BabyGuardianProps): BabyGuardian {
    return new BabyGuardian(props);
  }
 
  isOwner(): boolean {
    return this.role === 'OWNER';
  }
}