refactor driver module (wip)
This commit is contained in:
@@ -1,36 +1,26 @@
|
||||
import type { GetAllTeamsErrorCode, GetAllTeamsResult } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import type { GetAllTeamsResult } from '@core/racing/application/use-cases/GetAllTeamsUseCase';
|
||||
import { GetAllTeamsOutputDTO } from '../dtos/GetAllTeamsOutputDTO';
|
||||
|
||||
export type GetAllTeamsError = ApplicationErrorCode<GetAllTeamsErrorCode, { message: string }>;
|
||||
|
||||
export class AllTeamsPresenter {
|
||||
export class AllTeamsPresenter implements UseCaseOutputPort<GetAllTeamsResult> {
|
||||
private model: GetAllTeamsOutputDTO | null = null;
|
||||
|
||||
reset(): void {
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
present(result: Result<GetAllTeamsResult, GetAllTeamsError>): void {
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
throw new Error(error.details?.message ?? 'Failed to get teams');
|
||||
}
|
||||
|
||||
const output = result.unwrap();
|
||||
|
||||
present(result: GetAllTeamsResult): void {
|
||||
this.model = {
|
||||
teams: output.teams.map(team => ({
|
||||
teams: result.teams.map(team => ({
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
tag: team.tag,
|
||||
description: team.description,
|
||||
name: team.name.toString(),
|
||||
tag: team.tag.toString(),
|
||||
description: team.description?.toString() || '',
|
||||
memberCount: team.memberCount,
|
||||
leagues: team.leagues || [],
|
||||
leagues: team.leagues?.map(l => l.toString()) || [],
|
||||
// Note: specialization, region, languages not available in output
|
||||
})),
|
||||
totalCount: output.totalCount ?? output.teams.length,
|
||||
totalCount: result.totalCount ?? result.teams.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user