fix data flow issues
This commit is contained in:
92
apps/website/lib/view-models/SponsorshipViewModel.ts
Normal file
92
apps/website/lib/view-models/SponsorshipViewModel.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Sponsorship View Model
|
||||
*
|
||||
* View model for individual sponsorship data.
|
||||
*/
|
||||
export class SponsorshipViewModel {
|
||||
id: string;
|
||||
type: 'leagues' | 'teams' | 'drivers' | 'races' | 'platform';
|
||||
entityId: string;
|
||||
entityName: string;
|
||||
tier?: 'main' | 'secondary';
|
||||
status: 'active' | 'pending_approval' | 'approved' | 'rejected' | 'expired';
|
||||
applicationDate?: Date;
|
||||
approvalDate?: Date;
|
||||
rejectionReason?: string;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
price: number;
|
||||
impressions: number;
|
||||
impressionsChange?: number;
|
||||
engagement?: number;
|
||||
details?: string;
|
||||
entityOwner?: string;
|
||||
applicationMessage?: string;
|
||||
|
||||
constructor(data: any) {
|
||||
this.id = data.id;
|
||||
this.type = data.type;
|
||||
this.entityId = data.entityId;
|
||||
this.entityName = data.entityName;
|
||||
this.tier = data.tier;
|
||||
this.status = data.status;
|
||||
this.applicationDate = data.applicationDate ? new Date(data.applicationDate) : undefined;
|
||||
this.approvalDate = data.approvalDate ? new Date(data.approvalDate) : undefined;
|
||||
this.rejectionReason = data.rejectionReason;
|
||||
this.startDate = new Date(data.startDate);
|
||||
this.endDate = new Date(data.endDate);
|
||||
this.price = data.price;
|
||||
this.impressions = data.impressions;
|
||||
this.impressionsChange = data.impressionsChange;
|
||||
this.engagement = data.engagement;
|
||||
this.details = data.details;
|
||||
this.entityOwner = data.entityOwner;
|
||||
this.applicationMessage = data.applicationMessage;
|
||||
}
|
||||
|
||||
get formattedImpressions(): string {
|
||||
return this.impressions.toLocaleString();
|
||||
}
|
||||
|
||||
get formattedPrice(): string {
|
||||
return `$${this.price}`;
|
||||
}
|
||||
|
||||
get daysRemaining(): number {
|
||||
const now = new Date();
|
||||
const diffTime = this.endDate.getTime() - now.getTime();
|
||||
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
||||
}
|
||||
|
||||
get isExpiringSoon(): boolean {
|
||||
return this.daysRemaining > 0 && this.daysRemaining <= 30;
|
||||
}
|
||||
|
||||
get statusLabel(): string {
|
||||
const labels = {
|
||||
active: 'Active',
|
||||
pending_approval: 'Awaiting Approval',
|
||||
approved: 'Approved',
|
||||
rejected: 'Declined',
|
||||
expired: 'Expired',
|
||||
};
|
||||
return labels[this.status] || this.status;
|
||||
}
|
||||
|
||||
get typeLabel(): string {
|
||||
const labels = {
|
||||
leagues: 'League',
|
||||
teams: 'Team',
|
||||
drivers: 'Driver',
|
||||
races: 'Race',
|
||||
platform: 'Platform',
|
||||
};
|
||||
return labels[this.type] || this.type;
|
||||
}
|
||||
|
||||
get periodDisplay(): string {
|
||||
const start = this.startDate.toLocaleDateString('en-US', { month: 'short', year: 'numeric' });
|
||||
const end = this.endDate.toLocaleDateString('en-US', { month: 'short', year: 'numeric' });
|
||||
return `${start} - ${end}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user