Files
gridpilot.gg/apps/website/lib/view-models/SponsorSponsorshipsViewModel.ts
2025-12-17 22:17:02 +01:00

50 lines
1.5 KiB
TypeScript

import type { SponsorSponsorshipsDto } from '../dtos';
import { SponsorshipDetailViewModel } from './SponsorshipDetailViewModel';
/**
* Sponsor Sponsorships View Model
*
* View model for sponsor sponsorships data with UI-specific transformations.
*/
export class SponsorSponsorshipsViewModel {
sponsorId: string;
sponsorName: string;
sponsorships: SponsorshipDetailViewModel[];
constructor(dto: SponsorSponsorshipsDto) {
this.sponsorId = dto.sponsorId;
this.sponsorName = dto.sponsorName;
this.sponsorships = dto.sponsorships.map(s => new SponsorshipDetailViewModel(s));
}
/** UI-specific: Total sponsorships count */
get totalCount(): number {
return this.sponsorships.length;
}
/** UI-specific: Active sponsorships */
get activeSponsorships(): SponsorshipDetailViewModel[] {
return this.sponsorships.filter(s => s.status === 'active');
}
/** UI-specific: Active count */
get activeCount(): number {
return this.activeSponsorships.length;
}
/** UI-specific: Has sponsorships */
get hasSponsorships(): boolean {
return this.sponsorships.length > 0;
}
/** UI-specific: Total investment */
get totalInvestment(): number {
return this.sponsorships.reduce((sum, s) => sum + s.amount, 0);
}
/** UI-specific: Formatted total investment */
get formattedTotalInvestment(): string {
const firstCurrency = this.sponsorships[0]?.currency || 'USD';
return `${firstCurrency} ${this.totalInvestment.toLocaleString()}`;
}
}