refactor dashboard module
This commit is contained in:
@@ -5,6 +5,7 @@ import { Race } from '@core/racing/domain/entities/Race';
|
||||
import { Standing } from '@core/racing/domain/entities/Standing';
|
||||
import { Result as RaceResult } from '@core/racing/domain/entities/result/Result';
|
||||
import type { FeedItem } from '@core/social/domain/types/FeedItem';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { DashboardOverviewPresenter } from './DashboardOverviewPresenter';
|
||||
|
||||
@@ -143,7 +144,7 @@ describe('DashboardOverviewPresenter', () => {
|
||||
it('maps DashboardOverviewResult to DashboardOverviewDTO correctly', () => {
|
||||
const output = createOutput();
|
||||
|
||||
presenter.present(output);
|
||||
presenter.present(Result.ok(output));
|
||||
const dto = presenter.getResponseModel();
|
||||
|
||||
expect(dto.activeLeaguesCount).toBe(2);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type {
|
||||
DashboardOverviewResult,
|
||||
} from '@core/racing/application/use-cases/DashboardOverviewUseCase';
|
||||
@@ -13,22 +13,24 @@ import {
|
||||
DashboardFriendSummaryDTO,
|
||||
} from '../dtos/DashboardOverviewDTO';
|
||||
|
||||
export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOverviewResult> {
|
||||
export class DashboardOverviewPresenter {
|
||||
private responseModel: DashboardOverviewDTO | null = null;
|
||||
|
||||
present(result: DashboardOverviewResult): void {
|
||||
const currentDriver: DashboardDriverSummaryDTO | null = result.currentDriver
|
||||
present(result: Result<DashboardOverviewResult, unknown>): void {
|
||||
const data = result.unwrap();
|
||||
|
||||
const currentDriver: DashboardDriverSummaryDTO | null = data.currentDriver
|
||||
? {
|
||||
id: result.currentDriver.driver.id,
|
||||
name: String(result.currentDriver.driver.name),
|
||||
country: String(result.currentDriver.driver.country),
|
||||
avatarUrl: result.currentDriver.avatarUrl,
|
||||
rating: result.currentDriver.rating,
|
||||
globalRank: result.currentDriver.globalRank,
|
||||
totalRaces: result.currentDriver.totalRaces,
|
||||
wins: result.currentDriver.wins,
|
||||
podiums: result.currentDriver.podiums,
|
||||
consistency: result.currentDriver.consistency,
|
||||
id: data.currentDriver.driver.id,
|
||||
name: String(data.currentDriver.driver.name),
|
||||
country: String(data.currentDriver.driver.country),
|
||||
avatarUrl: data.currentDriver.avatarUrl,
|
||||
rating: data.currentDriver.rating,
|
||||
globalRank: data.currentDriver.globalRank,
|
||||
totalRaces: data.currentDriver.totalRaces,
|
||||
wins: data.currentDriver.wins,
|
||||
podiums: data.currentDriver.podiums,
|
||||
consistency: data.currentDriver.consistency,
|
||||
}
|
||||
: null;
|
||||
|
||||
@@ -43,13 +45,13 @@ export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOv
|
||||
isMyLeague: raceSummary.isMyLeague,
|
||||
});
|
||||
|
||||
const myUpcomingRaces: DashboardRaceSummaryDTO[] = result.myUpcomingRaces.map(mapRace);
|
||||
const otherUpcomingRaces: DashboardRaceSummaryDTO[] = result.otherUpcomingRaces.map(mapRace);
|
||||
const upcomingRaces: DashboardRaceSummaryDTO[] = result.upcomingRaces.map(mapRace);
|
||||
const myUpcomingRaces: DashboardRaceSummaryDTO[] = data.myUpcomingRaces.map(mapRace);
|
||||
const otherUpcomingRaces: DashboardRaceSummaryDTO[] = data.otherUpcomingRaces.map(mapRace);
|
||||
const upcomingRaces: DashboardRaceSummaryDTO[] = data.upcomingRaces.map(mapRace);
|
||||
|
||||
const nextRace: DashboardRaceSummaryDTO | null = result.nextRace ? mapRace(result.nextRace) : null;
|
||||
const nextRace: DashboardRaceSummaryDTO | null = data.nextRace ? mapRace(data.nextRace) : null;
|
||||
|
||||
const recentResults: DashboardRecentResultDTO[] = result.recentResults.map(resultSummary => ({
|
||||
const recentResults: DashboardRecentResultDTO[] = data.recentResults.map(resultSummary => ({
|
||||
raceId: resultSummary.race.id,
|
||||
raceName: String(resultSummary.race.track),
|
||||
leagueId: resultSummary.league?.id ? String(resultSummary.league.id) : null,
|
||||
@@ -60,7 +62,7 @@ export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOv
|
||||
}));
|
||||
|
||||
const leagueStandingsSummaries: DashboardLeagueStandingSummaryDTO[] =
|
||||
result.leagueStandingsSummaries.map(standing => ({
|
||||
data.leagueStandingsSummaries.map(standing => ({
|
||||
leagueId: String(standing.league.id),
|
||||
leagueName: String(standing.league.name),
|
||||
position: standing.standing?.position ? Number(standing.standing.position) : null,
|
||||
@@ -68,7 +70,7 @@ export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOv
|
||||
points: standing.standing?.points ? Number(standing.standing.points) : null,
|
||||
}));
|
||||
|
||||
const feedItems: DashboardFeedItemSummaryDTO[] = result.feedSummary.items.map(item => ({
|
||||
const feedItems: DashboardFeedItemSummaryDTO[] = data.feedSummary.items.map(item => ({
|
||||
id: item.id,
|
||||
type: String(item.type),
|
||||
headline: item.headline,
|
||||
@@ -79,11 +81,11 @@ export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOv
|
||||
}));
|
||||
|
||||
const feedSummary: DashboardFeedSummaryDTO = {
|
||||
notificationCount: result.feedSummary.notificationCount,
|
||||
notificationCount: data.feedSummary.notificationCount,
|
||||
items: feedItems,
|
||||
};
|
||||
|
||||
const friends: DashboardFriendSummaryDTO[] = result.friends.map(friend => ({
|
||||
const friends: DashboardFriendSummaryDTO[] = data.friends.map(friend => ({
|
||||
id: friend.driver.id,
|
||||
name: String(friend.driver.name),
|
||||
country: String(friend.driver.country),
|
||||
@@ -95,7 +97,7 @@ export class DashboardOverviewPresenter implements UseCaseOutputPort<DashboardOv
|
||||
myUpcomingRaces,
|
||||
otherUpcomingRaces,
|
||||
upcomingRaces,
|
||||
activeLeaguesCount: result.activeLeaguesCount,
|
||||
activeLeaguesCount: data.activeLeaguesCount,
|
||||
nextRace,
|
||||
recentResults,
|
||||
leagueStandingsSummaries,
|
||||
|
||||
Reference in New Issue
Block a user