import type { AssessorRepository } from '../../src/persistence/assessor-repository'; import { buildPolicyAnalysisOverview, type PolicyAnalysisOverview } from '../../src/domain/policy-analysis-overview'; import { RepositoryNotFoundError } from '../../src/persistence/repository-errors'; export interface GpoPolicyAnalysisOverviewServiceOptions { now?: () => Date; } export class GpoPolicyAnalysisOverviewService { private readonly now: () => Date; constructor( private readonly repository: AssessorRepository, options: GpoPolicyAnalysisOverviewServiceOptions = {} ) { this.now = options.now ?? (() => new Date()); } async get(projectId: string): Promise { if (!await this.repository.getProject(projectId)) { throw new RepositoryNotFoundError(`Projekt ${projectId} ist nicht vorhanden.`); } const [identityAnalyses, profiles, aggregations, evaluations, findingRuns, processingRuns, baselineRecords, baselineAnalyses] = await Promise.all([ this.repository.listGpoPolicyAnalyses(projectId), this.repository.listEnvironmentProfiles(projectId), this.repository.listPolicySnapshotAggregations(projectId), this.repository.listPolicyEvaluations(projectId), this.repository.listPolicyFindingRuns(projectId), this.repository.listProjectProcessingRuns(projectId), this.repository.listMicrosoftSecurityBaselines(), this.repository.listMicrosoftSecurityBaselineAnalyses() ]); return buildPolicyAnalysisOverview({ projectId, generatedAt: this.now().toISOString(), identityAnalyses, profiles, aggregations, evaluations, findingRuns, processingRuns, baselineRecords, baselineAnalyses }); } }