refactor league module (wip)
This commit is contained in:
@@ -40,7 +40,7 @@ import type { LeagueScoringConfigViewModel } from './presenters/LeagueScoringCon
|
||||
import type { LeagueScoringPresetsViewModel } from './presenters/LeagueScoringPresetsPresenter';
|
||||
|
||||
// Core imports
|
||||
import type { Logger } from '@core/shared/application/Logger';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
// Use cases
|
||||
import { ApproveLeagueJoinRequestUseCase } from '@core/racing/application/use-cases/ApproveLeagueJoinRequestUseCase';
|
||||
@@ -58,7 +58,6 @@ import { GetLeagueSeasonsUseCase } from '@core/racing/application/use-cases/GetL
|
||||
import { GetLeagueStandingsUseCase } from '@core/racing/application/use-cases/GetLeagueStandingsUseCase';
|
||||
import { GetLeagueStatsUseCase } from '@core/racing/application/use-cases/GetLeagueStatsUseCase';
|
||||
import { GetLeagueWalletUseCase } from '@core/racing/application/use-cases/GetLeagueWalletUseCase';
|
||||
import { GetRaceProtestsUseCase } from '@core/racing/application/use-cases/GetRaceProtestsUseCase';
|
||||
import { GetSeasonSponsorshipsUseCase } from '@core/racing/application/use-cases/GetSeasonSponsorshipsUseCase';
|
||||
import { GetTotalLeaguesUseCase } from '@core/racing/application/use-cases/GetTotalLeaguesUseCase';
|
||||
import { JoinLeagueUseCase } from '@core/racing/application/use-cases/JoinLeagueUseCase';
|
||||
@@ -80,10 +79,9 @@ import { GetLeagueProtestsPresenter } from './presenters/GetLeagueProtestsPresen
|
||||
import { GetLeagueSeasonsPresenter } from './presenters/GetLeagueSeasonsPresenter';
|
||||
import { GetSeasonSponsorshipsPresenter } from './presenters/GetSeasonSponsorshipsPresenter';
|
||||
import { JoinLeaguePresenter } from './presenters/JoinLeaguePresenter';
|
||||
import { LeagueAdminPresenter } from './presenters/LeagueAdminPresenter';
|
||||
import { LeagueConfigPresenter } from './presenters/LeagueConfigPresenter';
|
||||
import { LeagueJoinRequestsPresenter } from './presenters/LeagueJoinRequestsPresenter';
|
||||
import { LeagueSchedulePresenter } from './presenters/LeagueSchedulePresenter';
|
||||
import { LeagueSchedulePresenter, LeagueRacesPresenter } from './presenters/LeagueSchedulePresenter';
|
||||
import { LeagueScoringConfigPresenter } from './presenters/LeagueScoringConfigPresenter';
|
||||
import { LeagueScoringPresetsPresenter } from './presenters/LeagueScoringPresetsPresenter';
|
||||
import { LeagueStandingsPresenter } from './presenters/LeagueStandingsPresenter';
|
||||
@@ -93,8 +91,59 @@ import { RemoveLeagueMemberPresenter } from './presenters/RemoveLeagueMemberPres
|
||||
import { TotalLeaguesPresenter } from './presenters/TotalLeaguesPresenter';
|
||||
import { TransferLeagueOwnershipPresenter } from './presenters/TransferLeagueOwnershipPresenter';
|
||||
import { UpdateLeagueMemberRolePresenter } from './presenters/UpdateLeagueMemberRolePresenter';
|
||||
import { GetLeagueWalletPresenter } from './presenters/GetLeagueWalletPresenter';
|
||||
import { WithdrawFromLeagueWalletPresenter } from './presenters/WithdrawFromLeagueWalletPresenter';
|
||||
// Tokens
|
||||
import { LOGGER_TOKEN, GET_ALL_LEAGUES_WITH_CAPACITY_USE_CASE, GET_LEAGUE_STANDINGS_USE_CASE, GET_LEAGUE_STATS_USE_CASE, GET_LEAGUE_FULL_CONFIG_USE_CASE, GET_LEAGUE_SCORING_CONFIG_USE_CASE, LIST_LEAGUE_SCORING_PRESETS_USE_CASE, JOIN_LEAGUE_USE_CASE, TRANSFER_LEAGUE_OWNERSHIP_USE_CASE, CREATE_LEAGUE_WITH_SEASON_AND_SCORING_USE_CASE, GET_RACE_PROTESTS_USE_CASE, GET_TOTAL_LEAGUES_USE_CASE, GET_LEAGUE_JOIN_REQUESTS_USE_CASE, APPROVE_LEAGUE_JOIN_REQUEST_USE_CASE, REJECT_LEAGUE_JOIN_REQUEST_USE_CASE, REMOVE_LEAGUE_MEMBER_USE_CASE, UPDATE_LEAGUE_MEMBER_ROLE_USE_CASE, GET_LEAGUE_OWNER_SUMMARY_USE_CASE, GET_LEAGUE_PROTESTS_USE_CASE, GET_LEAGUE_SEASONS_USE_CASE, GET_LEAGUE_MEMBERSHIPS_USE_CASE, GET_LEAGUE_SCHEDULE_USE_CASE, GET_LEAGUE_ADMIN_PERMISSIONS_USE_CASE, GET_LEAGUE_WALLET_USE_CASE, WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE, GET_SEASON_SPONSORSHIPS_USE_CASE } from './LeagueProviders';
|
||||
import {
|
||||
LOGGER_TOKEN,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_USE_CASE,
|
||||
GET_LEAGUE_STANDINGS_USE_CASE,
|
||||
GET_LEAGUE_STATS_USE_CASE,
|
||||
GET_LEAGUE_FULL_CONFIG_USE_CASE,
|
||||
GET_LEAGUE_SCORING_CONFIG_USE_CASE,
|
||||
LIST_LEAGUE_SCORING_PRESETS_USE_CASE,
|
||||
JOIN_LEAGUE_USE_CASE,
|
||||
TRANSFER_LEAGUE_OWNERSHIP_USE_CASE,
|
||||
CREATE_LEAGUE_WITH_SEASON_AND_SCORING_USE_CASE,
|
||||
GET_TOTAL_LEAGUES_USE_CASE,
|
||||
GET_LEAGUE_JOIN_REQUESTS_USE_CASE,
|
||||
APPROVE_LEAGUE_JOIN_REQUEST_USE_CASE,
|
||||
REJECT_LEAGUE_JOIN_REQUEST_USE_CASE,
|
||||
REMOVE_LEAGUE_MEMBER_USE_CASE,
|
||||
UPDATE_LEAGUE_MEMBER_ROLE_USE_CASE,
|
||||
GET_LEAGUE_OWNER_SUMMARY_USE_CASE,
|
||||
GET_LEAGUE_PROTESTS_USE_CASE,
|
||||
GET_LEAGUE_SEASONS_USE_CASE,
|
||||
GET_LEAGUE_MEMBERSHIPS_USE_CASE,
|
||||
GET_LEAGUE_SCHEDULE_USE_CASE,
|
||||
GET_LEAGUE_ADMIN_PERMISSIONS_USE_CASE,
|
||||
GET_LEAGUE_WALLET_USE_CASE,
|
||||
WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE,
|
||||
GET_SEASON_SPONSORSHIPS_USE_CASE,
|
||||
GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN,
|
||||
GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN,
|
||||
LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN,
|
||||
APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
|
||||
CREATE_LEAGUE_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN,
|
||||
JOIN_LEAGUE_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN,
|
||||
REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
|
||||
REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN,
|
||||
TOTAL_LEAGUES_OUTPUT_PORT_TOKEN,
|
||||
TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN,
|
||||
UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN,
|
||||
GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
|
||||
WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
|
||||
} from './LeagueProviders';
|
||||
|
||||
@Injectable()
|
||||
export class LeagueService {
|
||||
@@ -108,7 +157,6 @@ export class LeagueService {
|
||||
@Inject(JOIN_LEAGUE_USE_CASE) private readonly joinLeagueUseCase: JoinLeagueUseCase,
|
||||
@Inject(TRANSFER_LEAGUE_OWNERSHIP_USE_CASE) private readonly transferLeagueOwnershipUseCase: TransferLeagueOwnershipUseCase,
|
||||
@Inject(CREATE_LEAGUE_WITH_SEASON_AND_SCORING_USE_CASE) private readonly createLeagueWithSeasonAndScoringUseCase: CreateLeagueWithSeasonAndScoringUseCase,
|
||||
@Inject(GET_RACE_PROTESTS_USE_CASE) private readonly getRaceProtestsUseCase: GetRaceProtestsUseCase,
|
||||
@Inject(GET_TOTAL_LEAGUES_USE_CASE) private readonly getTotalLeaguesUseCase: GetTotalLeaguesUseCase,
|
||||
@Inject(GET_LEAGUE_JOIN_REQUESTS_USE_CASE) private readonly getLeagueJoinRequestsUseCase: GetLeagueJoinRequestsUseCase,
|
||||
@Inject(APPROVE_LEAGUE_JOIN_REQUEST_USE_CASE) private readonly approveLeagueJoinRequestUseCase: ApproveLeagueJoinRequestUseCase,
|
||||
@@ -125,120 +173,99 @@ export class LeagueService {
|
||||
@Inject(WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE) private readonly withdrawFromLeagueWalletUseCase: WithdrawFromLeagueWalletUseCase,
|
||||
@Inject(GET_SEASON_SPONSORSHIPS_USE_CASE) private readonly getSeasonSponsorshipsUseCase: GetSeasonSponsorshipsUseCase,
|
||||
@Inject(LOGGER_TOKEN) private readonly logger: Logger,
|
||||
// Injected presenters
|
||||
@Inject(GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN) private readonly allLeaguesWithCapacityPresenter: AllLeaguesWithCapacityPresenter,
|
||||
@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(GET_LEAGUE_JOIN_REQUESTS_USE_CASE) private readonly leagueJoinRequestsPresenter: LeagueJoinRequestsPresenter,
|
||||
@Inject(GET_LEAGUE_SCHEDULE_USE_CASE) private readonly leagueRacesPresenter: LeagueRacesPresenter,
|
||||
) {}
|
||||
|
||||
async getAllLeaguesWithCapacity(): Promise<AllLeaguesWithCapacityViewModel> {
|
||||
this.logger.debug('[LeagueService] Fetching all leagues with capacity.');
|
||||
|
||||
const result = await this.getAllLeaguesWithCapacityUseCase.execute();
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
return (this.getAllLeaguesWithCapacityUseCase.outputPort as AllLeaguesWithCapacityPresenter).getViewModel();
|
||||
await this.getAllLeaguesWithCapacityUseCase.execute();
|
||||
return this.allLeaguesWithCapacityPresenter.getViewModel();
|
||||
}
|
||||
|
||||
async getTotalLeagues(): Promise<TotalLeaguesDTO> {
|
||||
this.logger.debug('[LeagueService] Fetching total leagues count.');
|
||||
const result = await this.getTotalLeaguesUseCase.execute();
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
const presenter = new TotalLeaguesPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.getTotalLeaguesUseCase.execute({});
|
||||
return this.totalLeaguesPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueJoinRequests(leagueId: string): Promise<LeagueJoinRequestWithDriverDTO[]> {
|
||||
this.logger.debug(`[LeagueService] Fetching join requests for league: ${leagueId}.`);
|
||||
const presenter = new LeagueJoinRequestsPresenter();
|
||||
await this.getLeagueJoinRequestsUseCase.execute({ leagueId }, presenter);
|
||||
return presenter.getViewModel()!.joinRequests;
|
||||
await this.getLeagueJoinRequestsUseCase.execute({ leagueId });
|
||||
return this.leagueJoinRequestsPresenter.getViewModel()!.joinRequests;
|
||||
}
|
||||
|
||||
async approveLeagueJoinRequest(input: ApproveJoinRequestInputDTO): Promise<ApproveLeagueJoinRequestDTO> {
|
||||
this.logger.debug('Approving join request:', input);
|
||||
const result = await this.approveLeagueJoinRequestUseCase.execute({ leagueId: input.leagueId, requestId: input.requestId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
const presenter = new ApproveLeagueJoinRequestPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.approveLeagueJoinRequestUseCase.execute(input, this.approveLeagueJoinRequestPresenter);
|
||||
return this.approveLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async rejectLeagueJoinRequest(input: RejectJoinRequestInputDTO): Promise<RejectJoinRequestOutputDTO> {
|
||||
this.logger.debug('Rejecting join request:', input);
|
||||
const result = await this.rejectLeagueJoinRequestUseCase.execute({ requestId: input.requestId });
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return {
|
||||
success: false,
|
||||
error: error.code,
|
||||
};
|
||||
}
|
||||
const presenter = new RejectLeagueJoinRequestPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.rejectLeagueJoinRequestUseCase.execute({
|
||||
leagueId: input.leagueId,
|
||||
adminId: 'admin', // This should come from auth context
|
||||
requestId: input.requestId
|
||||
});
|
||||
return this.rejectLeagueJoinRequestPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getLeagueAdminPermissions(query: GetLeagueAdminPermissionsInputDTO): Promise<LeagueAdminPermissionsDTO> {
|
||||
this.logger.debug('Getting league admin permissions', { query });
|
||||
const result = await this.getLeagueAdminPermissionsUseCase.execute({ leagueId: query.leagueId, performerDriverId: query.performerDriverId });
|
||||
// This use case never errors
|
||||
const presenter = new GetLeagueAdminPermissionsPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.getLeagueAdminPermissionsUseCase.execute(query);
|
||||
return this.getLeagueAdminPermissionsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async removeLeagueMember(input: RemoveLeagueMemberInputDTO): Promise<RemoveLeagueMemberOutputDTO> {
|
||||
this.logger.debug('Removing league member', { leagueId: input.leagueId, targetDriverId: input.targetDriverId });
|
||||
const result = await this.removeLeagueMemberUseCase.execute({ leagueId: input.leagueId, targetDriverId: input.targetDriverId });
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return {
|
||||
success: false,
|
||||
error: error.code,
|
||||
};
|
||||
}
|
||||
const presenter = new RemoveLeagueMemberPresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.removeLeagueMemberUseCase.execute(input);
|
||||
return this.removeLeagueMemberPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async updateLeagueMemberRole(input: UpdateLeagueMemberRoleInputDTO): Promise<UpdateLeagueMemberRoleOutputDTO> {
|
||||
this.logger.debug('Updating league member role', { leagueId: input.leagueId, targetDriverId: input.targetDriverId, newRole: input.newRole });
|
||||
const result = await this.updateLeagueMemberRoleUseCase.execute({ leagueId: input.leagueId, targetDriverId: input.targetDriverId, newRole: input.newRole });
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return {
|
||||
success: false,
|
||||
error: error.code,
|
||||
};
|
||||
}
|
||||
const presenter = new UpdateLeagueMemberRolePresenter();
|
||||
presenter.present(result.unwrap());
|
||||
return presenter.getViewModel()!;
|
||||
await this.updateLeagueMemberRoleUseCase.execute(input);
|
||||
return this.updateLeagueMemberRolePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getLeagueOwnerSummary(query: GetLeagueOwnerSummaryQueryDTO): Promise<LeagueOwnerSummaryDTO> {
|
||||
this.logger.debug('Getting league owner summary:', query);
|
||||
const presenter = new GetLeagueOwnerSummaryPresenter();
|
||||
await this.getLeagueOwnerSummaryUseCase.execute({ leagueId: query.leagueId } as any, presenter);
|
||||
return presenter.getViewModel()!;
|
||||
await this.getLeagueOwnerSummaryUseCase.execute(query);
|
||||
return this.getLeagueOwnerSummaryPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getLeagueFullConfig(query: GetLeagueAdminConfigQueryDTO): Promise<LeagueConfigFormModelDTO | null> {
|
||||
this.logger.debug('Getting league full config', { query });
|
||||
|
||||
try {
|
||||
const result = await this.getLeagueFullConfigUseCase.execute({ leagueId: query.leagueId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error('Error getting league full config', new Error(result.unwrapErr().code));
|
||||
return null;
|
||||
}
|
||||
const presenter = new LeagueConfigPresenter();
|
||||
presenter.present(result.unwrap() as any);
|
||||
return presenter.getViewModel();
|
||||
await this.getLeagueFullConfigUseCase.execute(query);
|
||||
return this.leagueConfigPresenter.getViewModel();
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting league full config', error instanceof Error ? error : new Error(String(error)));
|
||||
return null;
|
||||
@@ -247,71 +274,44 @@ export class LeagueService {
|
||||
|
||||
async getLeagueProtests(query: GetLeagueProtestsQueryDTO): Promise<LeagueAdminProtestsDTO> {
|
||||
this.logger.debug('Getting league protests:', query);
|
||||
const result = await this.getLeagueProtestsUseCase.execute({ leagueId: query.leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
return (this.getLeagueProtestsUseCase.outputPort as GetLeagueProtestsPresenter).getResponseModel()!;
|
||||
await this.getLeagueProtestsUseCase.execute(query);
|
||||
return this.leagueProtestsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueSeasons(query: GetLeagueSeasonsQueryDTO): Promise<LeagueSeasonSummaryDTO[]> {
|
||||
this.logger.debug('Getting league seasons:', query);
|
||||
const result = await this.getLeagueSeasonsUseCase.execute({ leagueId: query.leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
return (this.getLeagueSeasonsUseCase.output as GetLeagueSeasonsPresenter).getResponseModel()!;
|
||||
await this.getLeagueSeasonsUseCase.execute(query);
|
||||
return this.getLeagueSeasonsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueMemberships(leagueId: string): Promise<LeagueMembershipsDTO> {
|
||||
this.logger.debug('Getting league memberships', { leagueId });
|
||||
const presenter = new GetLeagueMembershipsPresenter();
|
||||
await this.getLeagueMembershipsUseCase.execute({ leagueId }, presenter);
|
||||
return presenter.getViewModel()!.memberships;
|
||||
await this.getLeagueMembershipsUseCase.execute({ leagueId });
|
||||
return this.getLeagueMembershipsPresenter.getViewModel()!.memberships;
|
||||
}
|
||||
|
||||
async getLeagueStandings(leagueId: string): Promise<LeagueStandingsDTO> {
|
||||
this.logger.debug('Getting league standings', { leagueId });
|
||||
const result = await this.getLeagueStandingsUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
return (this.getLeagueStandingsUseCase.outputPort as LeagueStandingsPresenter).getResponseModel()!;
|
||||
await this.getLeagueStandingsUseCase.execute({ leagueId });
|
||||
return this.leagueStandingsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
async getLeagueSchedule(leagueId: string): Promise<LeagueScheduleDTO> {
|
||||
this.logger.debug('Getting league schedule', { leagueId });
|
||||
|
||||
const [scheduleResult, leagueConfigResult] = await Promise.all([
|
||||
this.getLeagueScheduleUseCase.execute({ leagueId }),
|
||||
this.getLeagueFullConfigUseCase.execute({ leagueId }),
|
||||
]);
|
||||
|
||||
if (scheduleResult.isErr()) {
|
||||
throw new Error(scheduleResult.unwrapErr().code);
|
||||
}
|
||||
|
||||
const leagueName = leagueConfigResult.isOk()
|
||||
? leagueConfigResult.unwrap().league.name.toString()
|
||||
: undefined;
|
||||
|
||||
const presenter = new LeagueSchedulePresenter();
|
||||
presenter.present(scheduleResult.unwrap(), leagueName);
|
||||
return presenter.getViewModel()!;
|
||||
await this.getLeagueScheduleUseCase.execute({ leagueId });
|
||||
return this.leagueSchedulePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getLeagueStats(leagueId: string): Promise<LeagueStatsDTO> {
|
||||
this.logger.debug('Getting league stats', { leagueId });
|
||||
const result = await this.getLeagueStatsUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
await this.getLeagueStatsUseCase.execute({ leagueId });
|
||||
return this.leagueStatsPresenter.getResponseModel()!;
|
||||
}
|
||||
|
||||
private async getLeagueAdminComposite(leagueId: string): Promise<LeagueAdminDTO> {
|
||||
this.logger.debug('Fetching composite league admin data', { leagueId });
|
||||
|
||||
async getLeagueAdmin(leagueId: string): Promise<LeagueAdminDTO> {
|
||||
this.logger.debug('Getting league admin data', { leagueId });
|
||||
|
||||
const [fullConfigResult, joinRequests, protests, seasons] = await Promise.all([
|
||||
this.getLeagueFullConfigUseCase.execute({ leagueId }),
|
||||
this.getLeagueJoinRequests(leagueId),
|
||||
@@ -323,37 +323,19 @@ export class LeagueService {
|
||||
throw new Error(fullConfigResult.unwrapErr().code);
|
||||
}
|
||||
|
||||
const fullConfig = fullConfigResult.unwrap();
|
||||
const league = fullConfig.league;
|
||||
await this.getLeagueOwnerSummaryUseCase.execute({ leagueId });
|
||||
const ownerSummary = this.getLeagueOwnerSummaryPresenter.getViewModel()!;
|
||||
|
||||
const ownerSummaryResult = await this.getLeagueOwnerSummaryUseCase.execute({ ownerId: league.ownerId.toString() });
|
||||
if (ownerSummaryResult.isErr()) {
|
||||
throw new Error(ownerSummaryResult.unwrapErr().code);
|
||||
}
|
||||
const configForm = this.leagueConfigPresenter.getViewModel();
|
||||
|
||||
const ownerSummaryPresenter = new GetLeagueOwnerSummaryPresenter();
|
||||
ownerSummaryPresenter.present(ownerSummaryResult.unwrap());
|
||||
const ownerSummary = ownerSummaryPresenter.getViewModel()!;
|
||||
|
||||
const configPresenter = new LeagueConfigPresenter();
|
||||
configPresenter.present(fullConfig);
|
||||
const configForm = configPresenter.getViewModel();
|
||||
|
||||
const adminPresenter = new LeagueAdminPresenter();
|
||||
adminPresenter.present({
|
||||
// For now, return a simple structure since we don't have a LeagueAdminPresenter
|
||||
return {
|
||||
joinRequests: joinRequests,
|
||||
ownerSummary,
|
||||
config: configForm,
|
||||
config: { form: configForm },
|
||||
protests,
|
||||
seasons,
|
||||
});
|
||||
|
||||
return adminPresenter.getViewModel();
|
||||
}
|
||||
|
||||
async getLeagueAdmin(leagueId: string): Promise<LeagueAdminDTO> {
|
||||
this.logger.debug('Getting league admin data', { leagueId });
|
||||
return this.getLeagueAdminComposite(leagueId);
|
||||
};
|
||||
}
|
||||
|
||||
async createLeague(input: CreateLeagueInputDTO): Promise<CreateLeagueViewModel> {
|
||||
@@ -370,10 +352,7 @@ export class LeagueService {
|
||||
enableNationsChampionship: false,
|
||||
enableTrophyChampionship: false,
|
||||
};
|
||||
const result = await this.createLeagueWithSeasonAndScoringUseCase.execute(command);
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
await this.createLeagueWithSeasonAndScoringUseCase.execute(command);
|
||||
return this.createLeaguePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
@@ -381,11 +360,7 @@ export class LeagueService {
|
||||
this.logger.debug('Getting league scoring config', { leagueId });
|
||||
|
||||
try {
|
||||
const result = await this.getLeagueScoringConfigUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
this.logger.error('Error getting league scoring config', new Error(result.unwrapErr().code));
|
||||
return null;
|
||||
}
|
||||
await this.getLeagueScoringConfigUseCase.execute({ leagueId });
|
||||
return this.leagueScoringConfigPresenter.getViewModel();
|
||||
} catch (error) {
|
||||
this.logger.error('Error getting league scoring config', error instanceof Error ? error : new Error(String(error)));
|
||||
@@ -396,61 +371,35 @@ export class LeagueService {
|
||||
async listLeagueScoringPresets(): Promise<LeagueScoringPresetsViewModel> {
|
||||
this.logger.debug('Listing league scoring presets');
|
||||
|
||||
const result = await this.listLeagueScoringPresetsUseCase.execute({});
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
await this.listLeagueScoringPresetsUseCase.execute({});
|
||||
return this.leagueScoringPresetsPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async joinLeague(leagueId: string, driverId: string): Promise<JoinLeagueOutputDTO> {
|
||||
this.logger.debug('Joining league', { leagueId, driverId });
|
||||
|
||||
const result = await this.joinLeagueUseCase.execute({ leagueId, driverId });
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return {
|
||||
success: false,
|
||||
error: error.code,
|
||||
};
|
||||
}
|
||||
await this.joinLeagueUseCase.execute({ leagueId, driverId });
|
||||
return this.joinLeaguePresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async transferLeagueOwnership(leagueId: string, currentOwnerId: string, newOwnerId: string): Promise<TransferLeagueOwnershipOutputDTO> {
|
||||
this.logger.debug('Transferring league ownership', { leagueId, currentOwnerId, newOwnerId });
|
||||
|
||||
const result = await this.transferLeagueOwnershipUseCase.execute({ leagueId, currentOwnerId, newOwnerId });
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return {
|
||||
success: false,
|
||||
error: error.code,
|
||||
};
|
||||
}
|
||||
await this.transferLeagueOwnershipUseCase.execute({ leagueId, currentOwnerId, newOwnerId });
|
||||
return this.transferLeagueOwnershipPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
async getSeasonSponsorships(seasonId: string): Promise<GetSeasonSponsorshipsOutputDTO> {
|
||||
this.logger.debug('Getting season sponsorships', { seasonId });
|
||||
|
||||
const result = await this.getSeasonSponsorshipsUseCase.execute({ seasonId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
return this.getSeasonSponsorshipsPresenter.getViewModel()!;
|
||||
await this.getSeasonSponsorshipsUseCase.execute({ seasonId });
|
||||
return this.seasonSponsorshipsPresenter.getViewModel()!;
|
||||
}
|
||||
|
||||
|
||||
async getRaces(leagueId: string): Promise<GetLeagueRacesOutputDTO> {
|
||||
this.logger.debug('Getting league races', { leagueId });
|
||||
|
||||
const result = await this.getLeagueScheduleUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
|
||||
await this.getLeagueScheduleUseCase.execute({ leagueId });
|
||||
return {
|
||||
races: this.leagueRacesPresenter.getViewModel()!,
|
||||
};
|
||||
@@ -458,26 +407,19 @@ export class LeagueService {
|
||||
|
||||
async getLeagueWallet(leagueId: string): Promise<GetLeagueWalletOutputDTO> {
|
||||
this.logger.debug('Getting league wallet', { leagueId });
|
||||
const result = await this.getLeagueWalletUseCase.execute({ leagueId });
|
||||
if (result.isErr()) {
|
||||
throw new Error(result.unwrapErr().code);
|
||||
}
|
||||
return result.unwrap() as GetLeagueWalletOutputDTO;
|
||||
await this.getLeagueWalletUseCase.execute({ leagueId });
|
||||
return this.getLeagueWalletPresenter.getResponseModel();
|
||||
}
|
||||
|
||||
async withdrawFromLeagueWallet(leagueId: string, input: WithdrawFromLeagueWalletInputDTO): Promise<WithdrawFromLeagueWalletOutputDTO> {
|
||||
this.logger.debug('Withdrawing from league wallet', { leagueId, amount: input.amount });
|
||||
const result = await this.withdrawFromLeagueWalletUseCase.execute({
|
||||
await this.withdrawFromLeagueWalletUseCase.execute({
|
||||
leagueId,
|
||||
requestedById: "admin",
|
||||
amount: input.amount,
|
||||
currency: input.currency as 'USD' | 'EUR' | 'GBP',
|
||||
seasonId: input.seasonId,
|
||||
destinationAccount: input.destinationAccount,
|
||||
reason: input.destinationAccount,
|
||||
});
|
||||
if (result.isErr()) {
|
||||
const error = result.unwrapErr();
|
||||
return { success: false, message: error.code };
|
||||
}
|
||||
return result.unwrap() as WithdrawFromLeagueWalletOutputDTO;
|
||||
return this.withdrawFromLeagueWalletPresenter.getResponseModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user