view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-24 12:14:08 +01:00
parent dde77e717a
commit 046852703f
94 changed files with 1333 additions and 4885 deletions

View File

@@ -4,6 +4,8 @@ import { ConsoleErrorReporter } from '@/lib/infrastructure/logging/ConsoleErrorR
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
import { Result } from '@/lib/contracts/Result';
import { Service, type DomainError } from '@/lib/contracts/services/Service';
import { LeagueMembershipsDTO } from '@/lib/types/generated/LeagueMembershipsDTO';
import { AllLeaguesWithCapacityDTO } from '@/lib/types/generated/AllLeaguesWithCapacityDTO';
export interface ProfileLeaguesPageDto {
ownedLeagues: Array<{
@@ -20,12 +22,6 @@ export interface ProfileLeaguesPageDto {
}>;
}
interface MembershipDTO {
driverId: string;
role: string;
status?: 'active' | 'inactive';
}
export class ProfileLeaguesService implements Service {
async getProfileLeagues(driverId: string): Promise<Result<ProfileLeaguesPageDto, DomainError>> {
try {
@@ -34,7 +30,7 @@ export class ProfileLeaguesService implements Service {
const errorReporter = new ConsoleErrorReporter();
const leaguesApiClient = new LeaguesApiClient(baseUrl, errorReporter, logger);
const leaguesDto = await leaguesApiClient.getAllWithCapacity();
const leaguesDto: AllLeaguesWithCapacityDTO = await leaguesApiClient.getAllWithCapacity();
if (!leaguesDto?.leagues) {
return Result.err({ type: 'notFound', message: 'Leagues not found' });
@@ -44,20 +40,13 @@ export class ProfileLeaguesService implements Service {
const leagueMemberships = await Promise.all(
leaguesDto.leagues.map(async (league) => {
try {
const membershipsDto = await leaguesApiClient.getMemberships(league.id);
let memberships: MembershipDTO[] = [];
if (membershipsDto && typeof membershipsDto === 'object') {
if ('members' in membershipsDto && Array.isArray((membershipsDto as { members?: unknown }).members)) {
memberships = (membershipsDto as { members: MembershipDTO[] }).members;
} else if ('memberships' in membershipsDto && Array.isArray((membershipsDto as { memberships?: unknown }).memberships)) {
memberships = (membershipsDto as { memberships: MembershipDTO[] }).memberships;
}
}
const membershipsDto: LeagueMembershipsDTO = await leaguesApiClient.getMemberships(league.id);
const memberships = membershipsDto.members || [];
const currentMembership = memberships.find((m) => m.driverId === driverId);
if (currentMembership && currentMembership.status === 'active') {
// Note: LeagueMemberDTO doesn't have status, assuming if they are in the list they are active
if (currentMembership) {
return {
leagueId: league.id,
name: league.name,