refactor
This commit is contained in:
@@ -13,12 +13,13 @@ export interface GetDashboardDataOutput {
|
||||
|
||||
export type GetDashboardDataErrorCode = 'REPOSITORY_ERROR';
|
||||
|
||||
export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, GetDashboardDataOutput, GetDashboardDataErrorCode> {
|
||||
export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, void, GetDashboardDataErrorCode> {
|
||||
constructor(
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<GetDashboardDataOutput>,
|
||||
) {}
|
||||
|
||||
async execute(input: GetDashboardDataInput = {}): Promise<Result<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>> {
|
||||
async execute(input: GetDashboardDataInput = {}): Promise<Result<void, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>> {
|
||||
try {
|
||||
// Placeholder implementation - would need repositories from identity and racing domains
|
||||
const totalUsers = 0;
|
||||
@@ -26,6 +27,15 @@ export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, G
|
||||
const totalRaces = 0;
|
||||
const totalLeagues = 0;
|
||||
|
||||
const resultModel: GetDashboardDataOutput = {
|
||||
totalUsers,
|
||||
activeUsers,
|
||||
totalRaces,
|
||||
totalLeagues,
|
||||
};
|
||||
|
||||
this.output.present(resultModel);
|
||||
|
||||
this.logger.info('Dashboard data retrieved', {
|
||||
totalUsers,
|
||||
activeUsers,
|
||||
@@ -33,21 +43,14 @@ export class GetDashboardDataUseCase implements UseCase<GetDashboardDataInput, G
|
||||
totalLeagues,
|
||||
});
|
||||
|
||||
const result = Result.ok<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>({
|
||||
totalUsers,
|
||||
activeUsers,
|
||||
totalRaces,
|
||||
totalLeagues,
|
||||
});
|
||||
return result;
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
const err = error as Error;
|
||||
this.logger.error('Failed to get dashboard data', err);
|
||||
const result = Result.err<GetDashboardDataOutput, ApplicationErrorCode<GetDashboardDataErrorCode, { message: string }>>({
|
||||
return Result.err({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
details: { message: err.message ?? 'Failed to get dashboard data' },
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user