Normalize API counters in the server mappers instead of route loaders

This commit is contained in:
2026-09-24 14:02:23 +02:00
parent b0163f6a4d
commit ba0a2373b5
6 changed files with 68 additions and 16 deletions
+20
View File
@@ -82,6 +82,26 @@ export function toPlaylist(dto: PlaylistDto): Playlist {
};
}
type ListeningStatsDto = components['schemas']['ListeningStatsResponse'];
export interface ListeningStats {
tracksThisWeek: number;
secondsThisWeek: number;
streakDays: number;
}
export function toCount(value: number | string | null | undefined): number {
return Number(value ?? 0) || 0;
}
export function toListeningStats(dto: ListeningStatsDto | null | undefined): ListeningStats {
return {
tracksThisWeek: toCount(dto?.tracksThisWeek),
secondsThisWeek: toCount(dto?.secondsThisWeek),
streakDays: toCount(dto?.streakDays)
};
}
export function toPage<D, T>(dto: PageDto<D>, map: (item: D) => T): Paged<T> {
return {
items: dto.items.map(map),