wip
This commit is contained in:
@@ -14,13 +14,13 @@ export class AllLeaguesWithCapacityPresenter implements IAllLeaguesWithCapacityP
|
||||
): AllLeaguesWithCapacityViewModel {
|
||||
const leagueItems: LeagueWithCapacityViewModel[] = leagues.map((league) => {
|
||||
const usedSlots = memberCounts.get(league.id) ?? 0;
|
||||
|
||||
|
||||
// Ensure we never expose an impossible state like 26/24:
|
||||
// clamp maxDrivers to at least usedSlots at the application boundary.
|
||||
const configuredMax = league.settings.maxDrivers ?? usedSlots;
|
||||
const safeMaxDrivers = Math.max(configuredMax, usedSlots);
|
||||
|
||||
return {
|
||||
const base: LeagueWithCapacityViewModel = {
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
description: league.description,
|
||||
@@ -30,15 +30,33 @@ export class AllLeaguesWithCapacityPresenter implements IAllLeaguesWithCapacityP
|
||||
maxDrivers: safeMaxDrivers,
|
||||
},
|
||||
createdAt: league.createdAt.toISOString(),
|
||||
socialLinks: league.socialLinks
|
||||
? {
|
||||
discordUrl: league.socialLinks.discordUrl,
|
||||
youtubeUrl: league.socialLinks.youtubeUrl,
|
||||
websiteUrl: league.socialLinks.websiteUrl,
|
||||
}
|
||||
: undefined,
|
||||
usedSlots,
|
||||
};
|
||||
|
||||
if (!league.socialLinks) {
|
||||
return base;
|
||||
}
|
||||
|
||||
const socialLinks: NonNullable<LeagueWithCapacityViewModel['socialLinks']> = {};
|
||||
|
||||
if (league.socialLinks.discordUrl) {
|
||||
socialLinks.discordUrl = league.socialLinks.discordUrl;
|
||||
}
|
||||
if (league.socialLinks.youtubeUrl) {
|
||||
socialLinks.youtubeUrl = league.socialLinks.youtubeUrl;
|
||||
}
|
||||
if (league.socialLinks.websiteUrl) {
|
||||
socialLinks.websiteUrl = league.socialLinks.websiteUrl;
|
||||
}
|
||||
|
||||
if (Object.keys(socialLinks).length === 0) {
|
||||
return base;
|
||||
}
|
||||
|
||||
return {
|
||||
...base,
|
||||
socialLinks,
|
||||
};
|
||||
});
|
||||
|
||||
this.viewModel = {
|
||||
|
||||
Reference in New Issue
Block a user