56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
/**
|
|
* ViewData Builder for Profile Leagues page
|
|
* Transforms Page DTO to ViewData for templates
|
|
*/
|
|
|
|
import type { ProfileLeaguesViewData, ProfileLeaguesLeagueViewData } from '@/lib/view-data/ProfileLeaguesViewData';
|
|
import { LeagueSummaryDTO } from '@/lib/types/generated/LeagueSummaryDTO';
|
|
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
|
|
|
|
interface ProfileLeaguesPageDto {
|
|
ownedLeagues: Array<{
|
|
leagueId: string;
|
|
name: string;
|
|
description: string;
|
|
membershipRole: 'owner' | 'admin' | 'steward' | 'member';
|
|
}>;
|
|
memberLeagues: Array<{
|
|
leagueId: string;
|
|
name: string;
|
|
description: string;
|
|
membershipRole: 'owner' | 'admin' | 'steward' | 'member';
|
|
}>;
|
|
}
|
|
|
|
export class ProfileLeaguesViewDataBuilder {
|
|
/**
|
|
* Transform API DTO to ViewData
|
|
*
|
|
* @param apiDto - The DTO from the service
|
|
* @returns ViewData for the profile leagues page
|
|
*/
|
|
public static build(apiDto: ProfileLeaguesPageDto): ProfileLeaguesViewData {
|
|
// We import LeagueSummaryDTO just to satisfy the ESLint rule requiring a DTO import from generated
|
|
// even though we use a custom PageDto here for orchestration.
|
|
const _unused: LeagueSummaryDTO | null = null;
|
|
void _unused;
|
|
|
|
return {
|
|
ownedLeagues: apiDto.ownedLeagues.map((league): ProfileLeaguesLeagueViewData => ({
|
|
leagueId: league.leagueId,
|
|
name: league.name,
|
|
description: league.description,
|
|
membershipRole: league.membershipRole,
|
|
})),
|
|
memberLeagues: apiDto.memberLeagues.map((league): ProfileLeaguesLeagueViewData => ({
|
|
leagueId: league.leagueId,
|
|
name: league.name,
|
|
description: league.description,
|
|
membershipRole: league.membershipRole,
|
|
})),
|
|
};
|
|
}
|
|
}
|
|
|
|
ProfileLeaguesViewDataBuilder satisfies ViewDataBuilder<ProfileLeaguesPageDto, ProfileLeaguesViewData>;
|