All files / src/application/specialist list-visible-specialists.use-case.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 3/3
100% Lines 5/5

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                                23x     8x   8x 6x     5x      
import { Specialist } from '../../domain/specialist/specialist';
import { SpecialistRepository } from './specialist-repository';
 
export interface ListVisibleSpecialistsInput {
  requestingUserId: string;
  /** Optional filter: only the professionals linked to this child. */
  babyId?: string;
}
 
/**
 * Everything the caller can see, optionally narrowed to one child.
 *
 * The filter is applied after the visibility query rather than inside it, and that ordering is the
 * security property: narrowing can only ever remove rows the caller was already allowed to see.
 */
export class ListVisibleSpecialistsUseCase {
  constructor(private readonly specialistRepository: SpecialistRepository) {}
 
  async execute(input: ListVisibleSpecialistsInput): Promise<Specialist[]> {
    const visible = await this.specialistRepository.findAllVisibleTo(input.requestingUserId);
 
    if (!input.babyId) {
      return visible;
    }
 
    return visible.filter((specialist) => specialist.babyIds.includes(input.babyId!));
  }
}