view models
This commit is contained in:
@@ -1,37 +1,51 @@
|
||||
import { MembershipFeeDto } from '../types/generated/MembershipFeeDto';
|
||||
import type { MembershipFeeDto } from '../types/generated';
|
||||
|
||||
export class MembershipFeeViewModel implements MembershipFeeDto {
|
||||
export class MembershipFeeViewModel {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
type: string;
|
||||
amount: number;
|
||||
enabled: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
constructor(dto: MembershipFeeDto) {
|
||||
this.id = dto.id;
|
||||
this.leagueId = dto.leagueId;
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
|
||||
// Note: The generated DTO is incomplete
|
||||
// These fields will need to be added when the OpenAPI spec is updated
|
||||
amount: number = 0;
|
||||
currency: string = 'USD';
|
||||
period: string = 'monthly';
|
||||
|
||||
/** UI-specific: Formatted amount */
|
||||
get formattedAmount(): string {
|
||||
return `${this.currency} ${this.amount.toFixed(2)}`;
|
||||
return `€${this.amount.toFixed(2)}`; // Assuming EUR
|
||||
}
|
||||
|
||||
/** UI-specific: Period display */
|
||||
get periodDisplay(): string {
|
||||
switch (this.period) {
|
||||
case 'monthly': return 'Monthly';
|
||||
case 'yearly': return 'Yearly';
|
||||
/** UI-specific: Type display */
|
||||
get typeDisplay(): string {
|
||||
switch (this.type) {
|
||||
case 'season': return 'Per Season';
|
||||
default: return this.period;
|
||||
case 'monthly': return 'Monthly';
|
||||
case 'per_race': return 'Per Race';
|
||||
default: return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
/** UI-specific: Amount per period */
|
||||
get amountPerPeriod(): string {
|
||||
return `${this.formattedAmount} ${this.periodDisplay.toLowerCase()}`;
|
||||
/** UI-specific: Status display */
|
||||
get statusDisplay(): string {
|
||||
return this.enabled ? 'Enabled' : 'Disabled';
|
||||
}
|
||||
|
||||
/** UI-specific: Status color */
|
||||
get statusColor(): string {
|
||||
return this.enabled ? 'green' : 'red';
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted created date */
|
||||
get formattedCreatedAt(): string {
|
||||
return this.createdAt.toLocaleString();
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted updated date */
|
||||
get formattedUpdatedAt(): string {
|
||||
return this.updatedAt.toLocaleString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user