view models
This commit is contained in:
@@ -1,14 +1,39 @@
|
||||
import type { LeagueJoinRequestDto } from '../dtos';
|
||||
import type { LeagueJoinRequestDTO } from '../types/generated/LeagueJoinRequestDTO';
|
||||
|
||||
/**
|
||||
* League join request view model
|
||||
* Transform from DTO to ViewModel with UI fields
|
||||
*/
|
||||
export interface LeagueJoinRequestViewModel extends LeagueJoinRequestDto {
|
||||
// Formatted request date
|
||||
formattedRequestedAt: string;
|
||||
// Whether the request can be approved by current user
|
||||
canApprove: boolean;
|
||||
// Whether the request can be rejected by current user
|
||||
canReject: boolean;
|
||||
export class LeagueJoinRequestViewModel implements LeagueJoinRequestDTO {
|
||||
id: string;
|
||||
leagueId: string;
|
||||
driverId: string;
|
||||
requestedAt: string;
|
||||
|
||||
private currentUserId: string;
|
||||
private isAdmin: boolean;
|
||||
|
||||
constructor(dto: LeagueJoinRequestDTO, currentUserId: string, isAdmin: boolean) {
|
||||
this.id = dto.id;
|
||||
this.leagueId = dto.leagueId;
|
||||
this.driverId = dto.driverId;
|
||||
this.requestedAt = dto.requestedAt;
|
||||
this.currentUserId = currentUserId;
|
||||
this.isAdmin = isAdmin;
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted request date */
|
||||
get formattedRequestedAt(): string {
|
||||
return new Date(this.requestedAt).toLocaleString();
|
||||
}
|
||||
|
||||
/** UI-specific: Whether the request can be approved by current user */
|
||||
get canApprove(): boolean {
|
||||
return this.isAdmin;
|
||||
}
|
||||
|
||||
/** UI-specific: Whether the request can be rejected by current user */
|
||||
get canReject(): boolean {
|
||||
return this.isAdmin;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user