This commit is contained in:
2025-12-11 21:06:25 +01:00
parent c49ea2598d
commit ec3ddc3a5c
227 changed files with 3496 additions and 2083 deletions

View File

@@ -1,34 +1,43 @@
import type { ITeamRepository } from '../../domain/repositories/ITeamRepository';
import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
import type { IAllTeamsPresenter } from '../presenters/IAllTeamsPresenter';
import type { AsyncUseCase } from '@gridpilot/shared/application';
import type {
IAllTeamsPresenter,
AllTeamsResultDTO,
} from '../presenters/IAllTeamsPresenter';
import type { UseCase } from '@gridpilot/shared/application';
import type { Team } from '../../domain/entities/Team';
/**
* Use Case for retrieving all teams.
* Orchestrates domain logic and delegates presentation to the presenter.
*/
export class GetAllTeamsUseCase
implements AsyncUseCase<void, void> {
implements UseCase<void, AllTeamsResultDTO, import('../presenters/IAllTeamsPresenter').AllTeamsViewModel, IAllTeamsPresenter>
{
constructor(
private readonly teamRepository: ITeamRepository,
private readonly teamMembershipRepository: ITeamMembershipRepository,
public readonly presenter: IAllTeamsPresenter,
) {}
async execute(): Promise<void> {
async execute(_input: void, presenter: IAllTeamsPresenter): Promise<void> {
presenter.reset();
const teams = await this.teamRepository.findAll();
// Enrich teams with member counts
const enrichedTeams = await Promise.all(
const enrichedTeams: Array<Team & { memberCount: number }> = await Promise.all(
teams.map(async (team) => {
const memberships = await this.teamMembershipRepository.findByTeamId(team.id);
const memberCount = await this.teamMembershipRepository.countByTeamId(team.id);
return {
...team,
memberCount: memberships.length,
memberCount,
};
})
}),
);
this.presenter.present(enrichedTeams as any);
const dto: AllTeamsResultDTO = {
teams: enrichedTeams,
};
presenter.present(dto);
}
}