refactor use cases
This commit is contained in:
@@ -135,65 +135,39 @@ import {
|
||||
} from './presenters/LeagueSeasonScheduleMutationPresenters';
|
||||
// Tokens
|
||||
import {
|
||||
APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
|
||||
APPROVE_LEAGUE_JOIN_REQUEST_USE_CASE,
|
||||
CREATE_LEAGUE_OUTPUT_PORT_TOKEN,
|
||||
CREATE_LEAGUE_SEASON_SCHEDULE_RACE_USE_CASE,
|
||||
CREATE_LEAGUE_WITH_SEASON_AND_SCORING_USE_CASE,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_USE_CASE,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_USE_CASE,
|
||||
GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_ADMIN_PERMISSIONS_USE_CASE,
|
||||
GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_FULL_CONFIG_USE_CASE,
|
||||
GET_LEAGUE_JOIN_REQUESTS_USE_CASE,
|
||||
GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_MEMBERSHIPS_USE_CASE,
|
||||
GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_ROSTER_JOIN_REQUESTS_USE_CASE,
|
||||
GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_ROSTER_MEMBERS_USE_CASE,
|
||||
GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_OWNER_SUMMARY_USE_CASE,
|
||||
GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_PROTESTS_USE_CASE,
|
||||
GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SCHEDULE_USE_CASE,
|
||||
GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SCORING_CONFIG_USE_CASE,
|
||||
GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SEASONS_USE_CASE,
|
||||
GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_STATS_USE_CASE,
|
||||
GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_STANDINGS_USE_CASE,
|
||||
GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_WALLET_USE_CASE,
|
||||
GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN,
|
||||
GET_SEASON_SPONSORSHIPS_USE_CASE,
|
||||
GET_TOTAL_LEAGUES_USE_CASE,
|
||||
JOIN_LEAGUE_OUTPUT_PORT_TOKEN,
|
||||
JOIN_LEAGUE_USE_CASE,
|
||||
LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN,
|
||||
LIST_LEAGUE_SCORING_PRESETS_USE_CASE,
|
||||
LOGGER_TOKEN,
|
||||
PUBLISH_LEAGUE_SEASON_SCHEDULE_USE_CASE,
|
||||
REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
|
||||
REJECT_LEAGUE_JOIN_REQUEST_USE_CASE,
|
||||
REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN,
|
||||
REMOVE_LEAGUE_MEMBER_USE_CASE,
|
||||
TOTAL_LEAGUES_OUTPUT_PORT_TOKEN,
|
||||
TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN,
|
||||
TRANSFER_LEAGUE_OWNERSHIP_USE_CASE,
|
||||
UNPUBLISH_LEAGUE_SEASON_SCHEDULE_USE_CASE,
|
||||
UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN,
|
||||
UPDATE_LEAGUE_MEMBER_ROLE_USE_CASE,
|
||||
UPDATE_LEAGUE_SEASON_SCHEDULE_RACE_USE_CASE,
|
||||
DELETE_LEAGUE_SEASON_SCHEDULE_RACE_USE_CASE,
|
||||
WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
|
||||
WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE,
|
||||
GET_LEAGUE_ROSTER_MEMBERS_USE_CASE,
|
||||
GET_LEAGUE_ROSTER_JOIN_REQUESTS_USE_CASE,
|
||||
} from './LeagueTokens';
|
||||
|
||||
@Injectable()
|
||||
@@ -240,52 +214,47 @@ export class LeagueService {
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
|
||||
// Injected presenters
|
||||
@Inject(GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN) private readonly allLeaguesWithCapacityPresenter: AllLeaguesWithCapacityPresenter,
|
||||
@Inject(GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN) private readonly allLeaguesWithCapacityAndScoringPresenter: AllLeaguesWithCapacityAndScoringPresenter,
|
||||
@Inject(GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN) private readonly leagueStandingsPresenter: LeagueStandingsPresenter,
|
||||
@Inject(GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN) private readonly leagueProtestsPresenter: GetLeagueProtestsPresenter,
|
||||
@Inject(GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN) private readonly seasonSponsorshipsPresenter: GetSeasonSponsorshipsPresenter,
|
||||
@Inject(LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN) private readonly leagueScoringPresetsPresenter: LeagueScoringPresetsPresenter,
|
||||
@Inject(APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN) private readonly approveLeagueJoinRequestPresenter: ApproveLeagueJoinRequestPresenter,
|
||||
@Inject(CREATE_LEAGUE_OUTPUT_PORT_TOKEN) private readonly createLeaguePresenter: CreateLeaguePresenter,
|
||||
@Inject(GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN) private readonly getLeagueAdminPermissionsPresenter: GetLeagueAdminPermissionsPresenter,
|
||||
@Inject(GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN) private readonly getLeagueMembershipsPresenter: GetLeagueMembershipsPresenter,
|
||||
@Inject(GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN) private readonly getLeagueOwnerSummaryPresenter: GetLeagueOwnerSummaryPresenter,
|
||||
@Inject(GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN) private readonly getLeagueSeasonsPresenter: GetLeagueSeasonsPresenter,
|
||||
@Inject(JOIN_LEAGUE_OUTPUT_PORT_TOKEN) private readonly joinLeaguePresenter: JoinLeaguePresenter,
|
||||
@Inject(GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN) private readonly leagueSchedulePresenter: LeagueSchedulePresenter,
|
||||
@Inject(GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN) private readonly leagueStatsPresenter: LeagueStatsPresenter,
|
||||
@Inject(REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN) private readonly rejectLeagueJoinRequestPresenter: RejectLeagueJoinRequestPresenter,
|
||||
@Inject(REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN) private readonly removeLeagueMemberPresenter: RemoveLeagueMemberPresenter,
|
||||
@Inject(TOTAL_LEAGUES_OUTPUT_PORT_TOKEN) private readonly totalLeaguesPresenter: TotalLeaguesPresenter,
|
||||
@Inject(TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN) private readonly transferLeagueOwnershipPresenter: TransferLeagueOwnershipPresenter,
|
||||
@Inject(UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN) private readonly updateLeagueMemberRolePresenter: UpdateLeagueMemberRolePresenter,
|
||||
@Inject(GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN) private readonly leagueConfigPresenter: LeagueConfigPresenter,
|
||||
@Inject(GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN) private readonly leagueScoringConfigPresenter: LeagueScoringConfigPresenter,
|
||||
@Inject(GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN) private readonly getLeagueWalletPresenter: GetLeagueWalletPresenter,
|
||||
@Inject(WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN) private readonly withdrawFromLeagueWalletPresenter: WithdrawFromLeagueWalletPresenter,
|
||||
@Inject(AllLeaguesWithCapacityPresenter) private readonly allLeaguesWithCapacityPresenter: AllLeaguesWithCapacityPresenter,
|
||||
@Inject(AllLeaguesWithCapacityAndScoringPresenter) private readonly allLeaguesWithCapacityAndScoringPresenter: AllLeaguesWithCapacityAndScoringPresenter,
|
||||
@Inject(LeagueStandingsPresenter) private readonly leagueStandingsPresenter: LeagueStandingsPresenter,
|
||||
@Inject(GetLeagueProtestsPresenter) private readonly leagueProtestsPresenter: GetLeagueProtestsPresenter,
|
||||
@Inject(GetSeasonSponsorshipsPresenter) private readonly seasonSponsorshipsPresenter: GetSeasonSponsorshipsPresenter,
|
||||
@Inject(LeagueScoringPresetsPresenter) private readonly leagueScoringPresetsPresenter: LeagueScoringPresetsPresenter,
|
||||
@Inject(ApproveLeagueJoinRequestPresenter) private readonly approveLeagueJoinRequestPresenter: ApproveLeagueJoinRequestPresenter,
|
||||
@Inject(CreateLeaguePresenter) private readonly createLeaguePresenter: CreateLeaguePresenter,
|
||||
@Inject(GetLeagueAdminPermissionsPresenter) private readonly getLeagueAdminPermissionsPresenter: GetLeagueAdminPermissionsPresenter,
|
||||
@Inject(GetLeagueMembershipsPresenter) private readonly getLeagueMembershipsPresenter: GetLeagueMembershipsPresenter,
|
||||
@Inject(GetLeagueOwnerSummaryPresenter) private readonly getLeagueOwnerSummaryPresenter: GetLeagueOwnerSummaryPresenter,
|
||||
@Inject(GetLeagueSeasonsPresenter) private readonly getLeagueSeasonsPresenter: GetLeagueSeasonsPresenter,
|
||||
@Inject(JoinLeaguePresenter) private readonly joinLeaguePresenter: JoinLeaguePresenter,
|
||||
@Inject(LeagueSchedulePresenter) private readonly leagueSchedulePresenter: LeagueSchedulePresenter,
|
||||
@Inject(LeagueStatsPresenter) private readonly leagueStatsPresenter: LeagueStatsPresenter,
|
||||
@Inject(RejectLeagueJoinRequestPresenter) private readonly rejectLeagueJoinRequestPresenter: RejectLeagueJoinRequestPresenter,
|
||||
@Inject(RemoveLeagueMemberPresenter) private readonly removeLeagueMemberPresenter: RemoveLeagueMemberPresenter,
|
||||
@Inject(TotalLeaguesPresenter) private readonly totalLeaguesPresenter: TotalLeaguesPresenter,
|
||||
@Inject(TransferLeagueOwnershipPresenter) private readonly transferLeagueOwnershipPresenter: TransferLeagueOwnershipPresenter,
|
||||
@Inject(UpdateLeagueMemberRolePresenter) private readonly updateLeagueMemberRolePresenter: UpdateLeagueMemberRolePresenter,
|
||||
@Inject(LeagueConfigPresenter) private readonly leagueConfigPresenter: LeagueConfigPresenter,
|
||||
@Inject(LeagueScoringConfigPresenter) private readonly leagueScoringConfigPresenter: LeagueScoringConfigPresenter,
|
||||
@Inject(GetLeagueWalletPresenter) private readonly getLeagueWalletPresenter: GetLeagueWalletPresenter,
|
||||
@Inject(WithdrawFromLeagueWalletPresenter) private readonly withdrawFromLeagueWalletPresenter: WithdrawFromLeagueWalletPresenter,
|
||||
@Inject(LeagueJoinRequestsPresenter) private readonly leagueJoinRequestsPresenter: LeagueJoinRequestsPresenter,
|
||||
|
||||
// Schedule mutation presenters
|
||||
@Inject(CreateLeagueSeasonScheduleRacePresenter)
|
||||
private readonly createLeagueSeasonScheduleRacePresenter: CreateLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(UpdateLeagueSeasonScheduleRacePresenter)
|
||||
private readonly updateLeagueSeasonScheduleRacePresenter: UpdateLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(DeleteLeagueSeasonScheduleRacePresenter)
|
||||
private readonly deleteLeagueSeasonScheduleRacePresenter: DeleteLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(PublishLeagueSeasonSchedulePresenter)
|
||||
private readonly publishLeagueSeasonSchedulePresenter: PublishLeagueSeasonSchedulePresenter,
|
||||
@Inject(UnpublishLeagueSeasonSchedulePresenter)
|
||||
private readonly unpublishLeagueSeasonSchedulePresenter: UnpublishLeagueSeasonSchedulePresenter,
|
||||
@Inject(CreateLeagueSeasonScheduleRacePresenter) private readonly createLeagueSeasonScheduleRacePresenter: CreateLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(UpdateLeagueSeasonScheduleRacePresenter) private readonly updateLeagueSeasonScheduleRacePresenter: UpdateLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(DeleteLeagueSeasonScheduleRacePresenter) private readonly deleteLeagueSeasonScheduleRacePresenter: DeleteLeagueSeasonScheduleRacePresenter,
|
||||
@Inject(PublishLeagueSeasonSchedulePresenter) private readonly publishLeagueSeasonSchedulePresenter: PublishLeagueSeasonSchedulePresenter,
|
||||
@Inject(UnpublishLeagueSeasonSchedulePresenter) private readonly unpublishLeagueSeasonSchedulePresenter: UnpublishLeagueSeasonSchedulePresenter,
|
||||
|
||||
// Roster admin read delegation
|
||||
@Inject(GET_LEAGUE_ROSTER_MEMBERS_USE_CASE)
|
||||
private readonly getLeagueRosterMembersUseCase: GetLeagueRosterMembersUseCase,
|
||||
@Inject(GET_LEAGUE_ROSTER_JOIN_REQUESTS_USE_CASE)
|
||||
private readonly getLeagueRosterJoinRequestsUseCase: GetLeagueRosterJoinRequestsUseCase,
|
||||
@Inject(GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN)
|
||||
@Inject(GetLeagueRosterMembersPresenter)
|
||||
private readonly getLeagueRosterMembersPresenter: GetLeagueRosterMembersPresenter,
|
||||
@Inject(GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN)
|
||||
@Inject(GetLeagueRosterJoinRequestsPresenter)
|
||||
private readonly getLeagueRosterJoinRequestsPresenter: GetLeagueRosterJoinRequestsPresenter,
|
||||
) {}
|
||||
|
||||
@@ -327,7 +296,11 @@ export class LeagueService {
|
||||
|
||||
async getTotalLeagues(): Promise<TotalLeaguesDTO> {
|
||||
this.logger.debug('[LeagueService] Fetching total leagues count.');
|
||||
await this.getTotalLeaguesUseCase.execute({});
|
||||
const result = await this.getTotalLeaguesUseCase.execute({});
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.totalLeaguesPresenter.present(result.unwrap());
|
||||
return this.totalLeaguesPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -345,8 +318,13 @@ export class LeagueService {
|
||||
await this.requireLeagueAdminPermissions(leagueId);
|
||||
|
||||
this.leagueJoinRequestsPresenter.reset?.();
|
||||
await this.getLeagueJoinRequestsUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueJoinRequestsUseCase.execute({ leagueId });
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.leagueJoinRequestsPresenter.present(result.unwrap());
|
||||
return this.leagueJoinRequestsPresenter.getViewModel()!.joinRequests;
|
||||
}
|
||||
|
||||
@@ -355,10 +333,8 @@ export class LeagueService {
|
||||
|
||||
await this.requireLeagueAdminPermissions(input.leagueId);
|
||||
|
||||
this.approveLeagueJoinRequestPresenter.reset?.();
|
||||
const result = await this.approveLeagueJoinRequestUseCase.execute(
|
||||
{ leagueId: input.leagueId, joinRequestId: input.requestId },
|
||||
this.approveLeagueJoinRequestPresenter,
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
@@ -379,6 +355,7 @@ export class LeagueService {
|
||||
throw new Error(err.code);
|
||||
}
|
||||
|
||||
this.approveLeagueJoinRequestPresenter.present(result.unwrap());
|
||||
return this.approveLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -387,10 +364,8 @@ export class LeagueService {
|
||||
|
||||
await this.requireLeagueAdminPermissions(input.leagueId);
|
||||
|
||||
this.rejectLeagueJoinRequestPresenter.reset?.();
|
||||
const result = await this.rejectLeagueJoinRequestUseCase.execute(
|
||||
{ leagueId: input.leagueId, joinRequestId: input.requestId },
|
||||
this.rejectLeagueJoinRequestPresenter,
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
@@ -411,6 +386,7 @@ export class LeagueService {
|
||||
throw new Error(err.code);
|
||||
}
|
||||
|
||||
this.rejectLeagueJoinRequestPresenter.present(result.unwrap());
|
||||
return this.rejectLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -419,10 +395,8 @@ export class LeagueService {
|
||||
|
||||
await this.requireLeagueAdminPermissions(leagueId);
|
||||
|
||||
this.approveLeagueJoinRequestPresenter.reset?.();
|
||||
const result = await this.approveLeagueJoinRequestUseCase.execute(
|
||||
{ leagueId, joinRequestId },
|
||||
this.approveLeagueJoinRequestPresenter,
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
@@ -443,6 +417,7 @@ export class LeagueService {
|
||||
throw new Error(err.code);
|
||||
}
|
||||
|
||||
this.approveLeagueJoinRequestPresenter.present(result.unwrap());
|
||||
return this.approveLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -451,16 +426,15 @@ export class LeagueService {
|
||||
|
||||
await this.requireLeagueAdminPermissions(leagueId);
|
||||
|
||||
this.rejectLeagueJoinRequestPresenter.reset?.();
|
||||
const result = await this.rejectLeagueJoinRequestUseCase.execute(
|
||||
{ leagueId, joinRequestId },
|
||||
this.rejectLeagueJoinRequestPresenter,
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new NotFoundException('Join request not found');
|
||||
}
|
||||
|
||||
this.rejectLeagueJoinRequestPresenter.present(result.unwrap());
|
||||
return this.rejectLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -469,11 +443,16 @@ export class LeagueService {
|
||||
|
||||
this.logger.debug('Getting league admin permissions', { leagueId: query.leagueId, performerDriverId: actor.driverId });
|
||||
|
||||
await this.getLeagueAdminPermissionsUseCase.execute({
|
||||
const result = await this.getLeagueAdminPermissionsUseCase.execute({
|
||||
leagueId: query.leagueId,
|
||||
performerDriverId: actor.driverId,
|
||||
});
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.getLeagueAdminPermissionsPresenter.present(result.unwrap());
|
||||
return this.getLeagueAdminPermissionsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -544,7 +523,11 @@ export class LeagueService {
|
||||
|
||||
async getLeagueOwnerSummary(query: GetLeagueOwnerSummaryQueryDTO): Promise<LeagueOwnerSummaryDTO> {
|
||||
this.logger.debug('Getting league owner summary:', query);
|
||||
await this.getLeagueOwnerSummaryUseCase.execute(query);
|
||||
const result = await this.getLeagueOwnerSummaryUseCase.execute(query);
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.getLeagueOwnerSummaryPresenter.present(result.unwrap());
|
||||
return this.getLeagueOwnerSummaryPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -562,19 +545,31 @@ export class LeagueService {
|
||||
|
||||
async getLeagueProtests(query: GetLeagueProtestsQueryDTO): Promise<LeagueAdminProtestsDTO> {
|
||||
this.logger.debug('Getting league protests:', query);
|
||||
await this.getLeagueProtestsUseCase.execute(query);
|
||||
const result = await this.getLeagueProtestsUseCase.execute(query);
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.leagueProtestsPresenter.present(result.unwrap());
|
||||
return this.leagueProtestsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueSeasons(query: GetLeagueSeasonsQueryDTO): Promise<LeagueSeasonSummaryDTO[]> {
|
||||
this.logger.debug('Getting league seasons:', query);
|
||||
await this.getLeagueSeasonsUseCase.execute(query);
|
||||
const result = await this.getLeagueSeasonsUseCase.execute(query);
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.getLeagueSeasonsPresenter.present(result.unwrap());
|
||||
return this.getLeagueSeasonsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueMemberships(leagueId: string): Promise<LeagueMembershipsDTO> {
|
||||
this.logger.debug('Getting league memberships', { leagueId });
|
||||
await this.getLeagueMembershipsUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueMembershipsUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.getLeagueMembershipsPresenter.present(result.unwrap());
|
||||
return this.getLeagueMembershipsPresenter.getViewModel()!.memberships;
|
||||
}
|
||||
|
||||
@@ -590,6 +585,7 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.getLeagueRosterMembersPresenter.present(result.unwrap());
|
||||
return this.getLeagueRosterMembersPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -605,12 +601,17 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.getLeagueRosterJoinRequestsPresenter.present(result.unwrap());
|
||||
return this.getLeagueRosterJoinRequestsPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getLeagueStandings(leagueId: string): Promise<LeagueStandingsDTO> {
|
||||
this.logger.debug('Getting league standings', { leagueId });
|
||||
await this.getLeagueStandingsUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueStandingsUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.leagueStandingsPresenter.present(result.unwrap());
|
||||
return this.leagueStandingsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -618,8 +619,13 @@ export class LeagueService {
|
||||
this.logger.debug('Getting league schedule', { leagueId, query });
|
||||
|
||||
const input: GetLeagueScheduleInput = query?.seasonId ? { leagueId, seasonId: query.seasonId } : { leagueId };
|
||||
await this.getLeagueScheduleUseCase.execute(input);
|
||||
const result = await this.getLeagueScheduleUseCase.execute(input);
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.leagueSchedulePresenter.present(result.unwrap());
|
||||
return this.leagueSchedulePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -639,6 +645,7 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.publishLeagueSeasonSchedulePresenter.present(result.unwrap());
|
||||
return this.publishLeagueSeasonSchedulePresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -658,6 +665,7 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.unpublishLeagueSeasonSchedulePresenter.present(result.unwrap());
|
||||
return this.unpublishLeagueSeasonSchedulePresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -686,6 +694,7 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.createLeagueSeasonScheduleRacePresenter.present(result.unwrap());
|
||||
return this.createLeagueSeasonScheduleRacePresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -718,6 +727,7 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.updateLeagueSeasonScheduleRacePresenter.present(result.unwrap());
|
||||
return this.updateLeagueSeasonScheduleRacePresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -735,12 +745,17 @@ export class LeagueService {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.deleteLeagueSeasonScheduleRacePresenter.present(result.unwrap());
|
||||
return this.deleteLeagueSeasonScheduleRacePresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueStats(leagueId: string): Promise<LeagueStatsDTO> {
|
||||
this.logger.debug('Getting league stats', { leagueId });
|
||||
await this.getLeagueStatsUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueStatsUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.leagueStatsPresenter.present(result.unwrap());
|
||||
return this.leagueStatsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
@@ -787,7 +802,11 @@ export class LeagueService {
|
||||
enableNationsChampionship: false,
|
||||
enableTrophyChampionship: false,
|
||||
};
|
||||
await this.createLeagueWithSeasonAndScoringUseCase.execute(command);
|
||||
const result = await this.createLeagueWithSeasonAndScoringUseCase.execute(command);
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.createLeaguePresenter.present(result.unwrap());
|
||||
return this.createLeaguePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -806,7 +825,11 @@ export class LeagueService {
|
||||
async listLeagueScoringPresets(): Promise<LeagueScoringPresetsViewModel> {
|
||||
this.logger.debug('Listing league scoring presets');
|
||||
|
||||
await this.listLeagueScoringPresetsUseCase.execute({});
|
||||
const result = await this.listLeagueScoringPresetsUseCase.execute({});
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.leagueScoringPresetsPresenter.present(result.unwrap());
|
||||
return this.leagueScoringPresetsPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -814,7 +837,11 @@ export class LeagueService {
|
||||
const actor = this.getActor();
|
||||
this.logger.debug('Joining league', { leagueId, actorDriverId: actor.driverId });
|
||||
|
||||
await this.joinLeagueUseCase.execute({ leagueId, driverId: actor.driverId });
|
||||
const result = await this.joinLeagueUseCase.execute({ leagueId, driverId: actor.driverId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.joinLeaguePresenter.present(result.unwrap());
|
||||
return this.joinLeaguePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -825,19 +852,28 @@ export class LeagueService {
|
||||
|
||||
const actor = this.getActor();
|
||||
|
||||
await this.transferLeagueOwnershipUseCase.execute({
|
||||
const result = await this.transferLeagueOwnershipUseCase.execute({
|
||||
leagueId,
|
||||
currentOwnerId: actor.driverId,
|
||||
newOwnerId: input.newOwnerId,
|
||||
});
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.transferLeagueOwnershipPresenter.present(result.unwrap());
|
||||
return this.transferLeagueOwnershipPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getSeasonSponsorships(seasonId: string): Promise<GetSeasonSponsorshipsOutputDTO> {
|
||||
this.logger.debug('Getting season sponsorships', { seasonId });
|
||||
|
||||
await this.getSeasonSponsorshipsUseCase.execute({ seasonId });
|
||||
const result = await this.getSeasonSponsorshipsUseCase.execute({ seasonId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.seasonSponsorshipsPresenter.present(result.unwrap());
|
||||
return this.seasonSponsorshipsPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -847,8 +883,13 @@ export class LeagueService {
|
||||
// `GetLeagueScheduleUseCase` is wired to `LeagueSchedulePresenter` (not `LeagueRacesPresenter`),
|
||||
// so `LeagueRacesPresenter.getViewModel()` can be null at runtime.
|
||||
this.leagueSchedulePresenter.reset?.();
|
||||
await this.getLeagueScheduleUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueScheduleUseCase.execute({ leagueId });
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.leagueSchedulePresenter.present(result.unwrap());
|
||||
return {
|
||||
races: this.leagueSchedulePresenter.getViewModel()?.races ?? [],
|
||||
};
|
||||
@@ -856,7 +897,11 @@ export class LeagueService {
|
||||
|
||||
async getLeagueWallet(leagueId: string): Promise<GetLeagueWalletOutputDTO> {
|
||||
this.logger.debug('Getting league wallet', { leagueId });
|
||||
await this.getLeagueWalletUseCase.execute({ leagueId });
|
||||
const result = await this.getLeagueWalletUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
this.getLeagueWalletPresenter.present(result.unwrap());
|
||||
return this.getLeagueWalletPresenter.getResponseModel();
|
||||
}
|
||||
|
||||
@@ -868,7 +913,7 @@ export class LeagueService {
|
||||
|
||||
const actor = this.getActor();
|
||||
|
||||
await this.withdrawFromLeagueWalletUseCase.execute({
|
||||
const result = await this.withdrawFromLeagueWalletUseCase.execute({
|
||||
leagueId,
|
||||
requestedById: actor.driverId,
|
||||
amount: input.amount,
|
||||
@@ -876,6 +921,11 @@ export class LeagueService {
|
||||
reason: input.destinationAccount,
|
||||
});
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
this.withdrawFromLeagueWalletPresenter.present(result.unwrap());
|
||||
return this.withdrawFromLeagueWalletPresenter.getResponseModel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user