website refactor
This commit is contained in:
38
apps/website/lib/page-queries/SponsorDashboardPageQuery.ts
Normal file
38
apps/website/lib/page-queries/SponsorDashboardPageQuery.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { SponsorService } from '@/lib/services/sponsors/SponsorService';
|
||||
import { SponsorDashboardViewDataBuilder } from '@/lib/builders/view-data/SponsorDashboardViewDataBuilder';
|
||||
import type { SponsorDashboardViewData } from '@/lib/view-data/SponsorDashboardViewData';
|
||||
|
||||
/**
|
||||
* Sponsor Dashboard Page Query
|
||||
*
|
||||
* Composes data for the sponsor dashboard page.
|
||||
* Maps domain errors to presentation errors.
|
||||
*/
|
||||
export class SponsorDashboardPageQuery implements PageQuery<SponsorDashboardViewData, string> {
|
||||
async execute(sponsorId: string): Promise<Result<SponsorDashboardViewData, string>> {
|
||||
const service = new SponsorService();
|
||||
|
||||
const dashboardResult = await service.getSponsorDashboard(sponsorId);
|
||||
if (dashboardResult.isErr()) {
|
||||
return Result.err(this.mapToPresentationError(dashboardResult.getError()));
|
||||
}
|
||||
|
||||
const dto = dashboardResult.unwrap();
|
||||
const viewData = SponsorDashboardViewDataBuilder.build(dto);
|
||||
|
||||
return Result.ok(viewData);
|
||||
}
|
||||
|
||||
private mapToPresentationError(domainError: { type: string }): string {
|
||||
switch (domainError.type) {
|
||||
case 'notFound':
|
||||
return 'Dashboard not found';
|
||||
case 'notImplemented':
|
||||
return 'Dashboard feature not yet implemented';
|
||||
default:
|
||||
return 'Failed to load dashboard';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user