integration tests
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
This commit is contained in:
81
core/leagues/application/use-cases/GetLeagueRosterUseCase.ts
Normal file
81
core/leagues/application/use-cases/GetLeagueRosterUseCase.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { LeagueRepository } from '../ports/LeagueRepository';
|
||||
import { LeagueRosterQuery } from '../ports/LeagueRosterQuery';
|
||||
import { LeagueEventPublisher, LeagueRosterAccessedEvent } from '../ports/LeagueEventPublisher';
|
||||
|
||||
export interface LeagueRosterResult {
|
||||
leagueId: string;
|
||||
members: Array<{
|
||||
driverId: string;
|
||||
name: string;
|
||||
role: 'owner' | 'admin' | 'steward' | 'member';
|
||||
joinDate: Date;
|
||||
}>;
|
||||
pendingRequests: Array<{
|
||||
requestId: string;
|
||||
driverId: string;
|
||||
name: string;
|
||||
requestDate: Date;
|
||||
}>;
|
||||
stats: {
|
||||
adminCount: number;
|
||||
driverCount: number;
|
||||
};
|
||||
}
|
||||
|
||||
export class GetLeagueRosterUseCase {
|
||||
constructor(
|
||||
private readonly leagueRepository: LeagueRepository,
|
||||
private readonly eventPublisher: LeagueEventPublisher,
|
||||
) {}
|
||||
|
||||
async execute(query: LeagueRosterQuery): Promise<LeagueRosterResult> {
|
||||
// Validate query
|
||||
if (!query.leagueId || query.leagueId.trim() === '') {
|
||||
throw new Error('League ID is required');
|
||||
}
|
||||
|
||||
// Find league
|
||||
const league = await this.leagueRepository.findById(query.leagueId);
|
||||
if (!league) {
|
||||
throw new Error(`League with id ${query.leagueId} not found`);
|
||||
}
|
||||
|
||||
// Get league members (simplified - in real implementation would get from membership repository)
|
||||
const members = await this.leagueRepository.getLeagueMembers(query.leagueId);
|
||||
|
||||
// Get pending requests (simplified)
|
||||
const pendingRequests = await this.leagueRepository.getPendingRequests(query.leagueId);
|
||||
|
||||
// Calculate stats
|
||||
const adminCount = members.filter(m => m.role === 'owner' || m.role === 'admin').length;
|
||||
const driverCount = members.filter(m => m.role === 'member').length;
|
||||
|
||||
// Emit event
|
||||
const event: LeagueRosterAccessedEvent = {
|
||||
type: 'LeagueRosterAccessedEvent',
|
||||
leagueId: query.leagueId,
|
||||
timestamp: new Date(),
|
||||
};
|
||||
await this.eventPublisher.emitLeagueRosterAccessed(event);
|
||||
|
||||
return {
|
||||
leagueId: query.leagueId,
|
||||
members: members.map(m => ({
|
||||
driverId: m.driverId,
|
||||
name: m.name,
|
||||
role: m.role,
|
||||
joinDate: m.joinDate,
|
||||
})),
|
||||
pendingRequests: pendingRequests.map(r => ({
|
||||
requestId: r.id,
|
||||
driverId: r.driverId,
|
||||
name: r.name,
|
||||
requestDate: r.requestDate,
|
||||
})),
|
||||
stats: {
|
||||
adminCount,
|
||||
driverCount,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user