Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { LeagueWalletViewDataBuilder } from '@/lib/builders/view-data/LeagueWalletViewDataBuilder';
|
|
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
|
import { type PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
|
import { Result } from '@/lib/contracts/Result';
|
|
import { LeagueWalletService } from '@/lib/services/leagues/LeagueWalletService';
|
|
import { LeagueWalletViewData } from '@/lib/view-data/LeagueWalletViewData';
|
|
|
|
export class LeagueWalletPageQuery implements PageQuery<LeagueWalletViewData, string, PresentationError> {
|
|
async execute(leagueId: string): Promise<Result<LeagueWalletViewData, PresentationError>> {
|
|
const service = new LeagueWalletService();
|
|
const result = await service.getWalletData(leagueId);
|
|
|
|
if (result.isErr()) {
|
|
return Result.err(mapToPresentationError(result.getError()));
|
|
}
|
|
|
|
const viewData = LeagueWalletViewDataBuilder.build({ ...result.unwrap(), leagueId });
|
|
return Result.ok(viewData);
|
|
}
|
|
|
|
static async execute(leagueId: string): Promise<Result<LeagueWalletViewData, PresentationError>> {
|
|
const query = new LeagueWalletPageQuery();
|
|
return query.execute(leagueId);
|
|
}
|
|
}
|