All files / src/application/baby list-user-babies.use-case.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 4/4
100% Lines 6/6

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            24x 24x       8x   8x 11x     11x      
import { Baby } from '../../domain/baby/baby';
import { BabyRepository } from './baby-repository';
import { BabyGuardianRepository } from './baby-guardian-repository';
 
export class ListUserBabiesUseCase {
  constructor(
    private readonly babyRepository: BabyRepository,
    private readonly babyGuardianRepository: BabyGuardianRepository,
  ) {}
 
  async execute(userId: string): Promise<Baby[]> {
    const guardianships = await this.babyGuardianRepository.findAllByUser(userId);
 
    const babies = await Promise.all(
      guardianships.map((guardianship) => this.babyRepository.findById(guardianship.babyId)),
    );
 
    return babies.filter((baby): baby is Baby => baby !== null);
  }
}