Files
gridpilot.gg/apps/website/lib/view-models/RequestAvatarGenerationViewModel.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

68 lines
1.8 KiB
TypeScript

import { RequestAvatarGenerationOutputDTO } from '@/lib/types/generated/RequestAvatarGenerationOutputDTO';
/**
* Request Avatar Generation View Model
*
* Represents the result of an avatar generation request
*/
import { ViewModel } from "../contracts/view-models/ViewModel";
export class RequestAvatarGenerationViewModel extends ViewModel {
success: boolean;
requestId?: string;
avatarUrls?: string[];
errorMessage?: string;
constructor(
dto:
| RequestAvatarGenerationOutputDTO
| {
success: boolean;
requestId?: string;
avatarUrls?: string[];
errorMessage?: string;
avatarUrl?: string;
error?: string;
},
) {
super();
this.success = dto.success;
if ('requestId' in dto && dto.requestId !== undefined) this.requestId = dto.requestId;
if ('avatarUrls' in dto && dto.avatarUrls !== undefined) {
this.avatarUrls = dto.avatarUrls;
} else if ('avatarUrl' in dto && dto.avatarUrl !== undefined) {
this.avatarUrls = [dto.avatarUrl];
}
if ('errorMessage' in dto && dto.errorMessage !== undefined) {
this.errorMessage = dto.errorMessage;
} else if ('error' in dto && dto.error !== undefined) {
this.errorMessage = dto.error;
}
}
/** UI-specific: Whether generation was successful */
get isSuccessful(): boolean {
return this.success;
}
/** UI-specific: Whether there was an error */
get hasError(): boolean {
return !!this.errorMessage;
}
/** UI-specific: Get first avatar URL */
get firstAvatarUrl(): string | undefined {
return this.avatarUrls?.[0];
}
get avatarUrl(): string | undefined {
return this.firstAvatarUrl;
}
get error(): string | undefined {
return this.errorMessage;
}
}