refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -143,32 +143,6 @@ export const GET_LEAGUE_WALLET_USE_CASE = 'GetLeagueWalletUseCase';
export const WITHDRAW_FROM_LEAGUE_WALLET_USE_CASE = 'WithdrawFromLeagueWalletUseCase';
export const GET_SEASON_SPONSORSHIPS_USE_CASE = 'GetSeasonSponsorshipsUseCase';
export const GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN = 'GetAllLeaguesWithCapacityOutputPort_TOKEN';
export const GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN = 'GetAllLeaguesWithCapacityAndScoringOutputPort_TOKEN';
export const GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN = 'GetLeagueStandingsOutputPort_TOKEN';
export const GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN = 'GetLeagueProtestsOutputPort_TOKEN';
export const GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN = 'GetSeasonSponsorshipsOutputPort_TOKEN';
export const LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN = 'ListLeagueScoringPresetsOutputPort_TOKEN';
export const APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'ApproveLeagueJoinRequestOutputPort_TOKEN';
export const CREATE_LEAGUE_OUTPUT_PORT_TOKEN = 'CreateLeagueOutputPort_TOKEN';
export const GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN = 'GetLeagueAdminPermissionsOutputPort_TOKEN';
export const GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN = 'GetLeagueMembershipsOutputPort_TOKEN';
export const GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN = 'GetLeagueRosterMembersOutputPort_TOKEN';
export const GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN = 'GetLeagueRosterJoinRequestsOutputPort_TOKEN';
export const GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN = 'GetLeagueOwnerSummaryOutputPort_TOKEN';
export const GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN = 'GetLeagueSeasonsOutputPort_TOKEN';
export const JOIN_LEAGUE_OUTPUT_PORT_TOKEN = 'JoinLeagueOutputPort_TOKEN';
export const GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN = 'GetLeagueScheduleOutputPort_TOKEN';
export const GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN = 'GetLeagueStatsOutputPort_TOKEN';
export const REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'RejectLeagueJoinRequestOutputPort_TOKEN';
export const REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN = 'RemoveLeagueMemberOutputPort_TOKEN';
export const TOTAL_LEAGUES_OUTPUT_PORT_TOKEN = 'TotalLeaguesOutputPort_TOKEN';
export const TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN = 'TransferLeagueOwnershipOutputPort_TOKEN';
export const UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN = 'UpdateLeagueMemberRoleOutputPort_TOKEN';
export const GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueFullConfigOutputPort_TOKEN';
export const GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueScoringConfigOutputPort_TOKEN';
export const GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'GetLeagueWalletOutputPort_TOKEN';
export const WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'WithdrawFromLeagueWalletOutputPort_TOKEN';
export const LeagueProviders: Provider[] = [
LeagueService,
@@ -227,133 +201,6 @@ export const LeagueProviders: Provider[] = [
DeleteLeagueSeasonScheduleRacePresenter,
PublishLeagueSeasonSchedulePresenter,
UnpublishLeagueSeasonSchedulePresenter,
// Output ports
{
provide: GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN,
useExisting: AllLeaguesWithCapacityPresenter,
},
{
provide: GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN,
useExisting: AllLeaguesWithCapacityAndScoringPresenter,
},
{
provide: GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN,
useExisting: LeagueStandingsPresenter,
},
{
provide: GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueProtestsPresenter,
},
{
provide: GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN,
useExisting: GetSeasonSponsorshipsPresenter,
},
{
provide: LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN,
useExisting: LeagueScoringPresetsPresenter,
},
{
provide: APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
useExisting: ApproveLeagueJoinRequestPresenter,
},
{
provide: CREATE_LEAGUE_OUTPUT_PORT_TOKEN,
useExisting: CreateLeaguePresenter,
},
{
provide: GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueAdminPermissionsPresenter,
},
{
provide: GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueMembershipsPresenter,
},
{
provide: GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueRosterMembersPresenter,
},
{
provide: GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueRosterJoinRequestsPresenter,
},
{
provide: GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueOwnerSummaryPresenter,
},
{
provide: GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueSeasonsPresenter,
},
{
provide: JOIN_LEAGUE_OUTPUT_PORT_TOKEN,
useExisting: JoinLeaguePresenter,
},
{
provide: GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN,
useExisting: LeagueSchedulePresenter,
},
{
provide: GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN,
useExisting: LeagueStatsPresenter,
},
{
provide: REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN,
useExisting: RejectLeagueJoinRequestPresenter,
},
{
provide: REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN,
useExisting: RemoveLeagueMemberPresenter,
},
{
provide: TOTAL_LEAGUES_OUTPUT_PORT_TOKEN,
useExisting: TotalLeaguesPresenter,
},
{
provide: TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN,
useExisting: TransferLeagueOwnershipPresenter,
},
{
provide: UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN,
useExisting: UpdateLeagueMemberRolePresenter,
},
{
provide: GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN,
useExisting: LeagueConfigPresenter,
},
{
provide: GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN,
useExisting: LeagueScoringConfigPresenter,
},
{
provide: GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
useExisting: GetLeagueWalletPresenter,
},
{
provide: WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
useExisting: WithdrawFromLeagueWalletPresenter,
},
// Schedule mutation output ports
{
provide: LeagueTokens.CREATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
useExisting: CreateLeagueSeasonScheduleRacePresenter,
},
{
provide: LeagueTokens.UPDATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
useExisting: UpdateLeagueSeasonScheduleRacePresenter,
},
{
provide: LeagueTokens.DELETE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
useExisting: DeleteLeagueSeasonScheduleRacePresenter,
},
{
provide: LeagueTokens.PUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN,
useExisting: PublishLeagueSeasonSchedulePresenter,
},
{
provide: LeagueTokens.UNPUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN,
useExisting: UnpublishLeagueSeasonSchedulePresenter,
},
// Use cases
{
@@ -370,7 +217,6 @@ export const LeagueProviders: Provider[] = [
seasonRepo: ISeasonRepository,
scoringRepo: import('@core/racing/domain/repositories/ILeagueScoringConfigRepository').ILeagueScoringConfigRepository,
gameRepo: import('@core/racing/domain/repositories/IGameRepository').IGameRepository,
output: AllLeaguesWithCapacityAndScoringPresenter,
) =>
new GetAllLeaguesWithCapacityAndScoringUseCase(
leagueRepo,
@@ -379,7 +225,6 @@ export const LeagueProviders: Provider[] = [
scoringRepo,
gameRepo,
{ getPresetById: getLeagueScoringPresetById },
output,
),
inject: [
LEAGUE_REPOSITORY_TOKEN,
@@ -387,7 +232,6 @@ export const LeagueProviders: Provider[] = [
SEASON_REPOSITORY_TOKEN,
LEAGUE_SCORING_CONFIG_REPOSITORY_TOKEN,
GAME_REPOSITORY_TOKEN,
GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN,
],
},
{
@@ -395,12 +239,10 @@ export const LeagueProviders: Provider[] = [
useFactory: (
standingRepo: IStandingRepository,
driverRepo: IDriverRepository,
output: LeagueStandingsPresenter,
) => new GetLeagueStandingsUseCase(standingRepo, driverRepo, output),
) => new GetLeagueStandingsUseCase(standingRepo, driverRepo),
inject: [
STANDING_REPOSITORY_TOKEN,
DRIVER_REPOSITORY_TOKEN,
GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN,
],
},
{
@@ -421,9 +263,9 @@ export const LeagueProviders: Provider[] = [
},
{
provide: GET_TOTAL_LEAGUES_USE_CASE,
useFactory: (leagueRepo: ILeagueRepository, output: TotalLeaguesPresenter) =>
new GetTotalLeaguesUseCase(leagueRepo, output),
inject: [LEAGUE_REPOSITORY_TOKEN, TOTAL_LEAGUES_OUTPUT_PORT_TOKEN],
useFactory: (leagueRepo: ILeagueRepository) =>
new GetTotalLeaguesUseCase(leagueRepo),
inject: [LEAGUE_REPOSITORY_TOKEN],
},
{
provide: GET_LEAGUE_JOIN_REQUESTS_USE_CASE,
@@ -431,9 +273,8 @@ export const LeagueProviders: Provider[] = [
membershipRepo: ILeagueMembershipRepository,
driverRepo: IDriverRepository,
leagueRepo: ILeagueRepository,
output: LeagueJoinRequestsPresenter,
) => new GetLeagueJoinRequestsUseCase(membershipRepo, driverRepo, leagueRepo, output),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN, LeagueJoinRequestsPresenter],
) => new GetLeagueJoinRequestsUseCase(membershipRepo, driverRepo, leagueRepo),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN],
},
{
provide: APPROVE_LEAGUE_JOIN_REQUEST_USE_CASE,
@@ -453,21 +294,30 @@ export const LeagueProviders: Provider[] = [
provide: REMOVE_LEAGUE_MEMBER_USE_CASE,
useFactory: (
membershipRepo: ILeagueMembershipRepository,
output: RemoveLeagueMemberPresenter,
) => new RemoveLeagueMemberUseCase(membershipRepo, output),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN],
) => new RemoveLeagueMemberUseCase(membershipRepo),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN],
},
{
provide: UPDATE_LEAGUE_MEMBER_ROLE_USE_CASE,
useFactory: (
membershipRepo: ILeagueMembershipRepository,
output: UpdateLeagueMemberRolePresenter,
) => new UpdateLeagueMemberRoleUseCase(membershipRepo, output),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN],
) => new UpdateLeagueMemberRoleUseCase(membershipRepo),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN],
},
{
provide: GET_LEAGUE_OWNER_SUMMARY_USE_CASE,
useClass: GetLeagueOwnerSummaryUseCase,
useFactory: (
leagueRepo: ILeagueRepository,
driverRepo: IDriverRepository,
leagueMembershipRepo: ILeagueMembershipRepository,
standingRepo: IStandingRepository,
) => new GetLeagueOwnerSummaryUseCase(leagueRepo, driverRepo, leagueMembershipRepo, standingRepo),
inject: [
LEAGUE_REPOSITORY_TOKEN,
DRIVER_REPOSITORY_TOKEN,
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
STANDING_REPOSITORY_TOKEN,
],
},
{
provide: GET_LEAGUE_PROTESTS_USE_CASE,
@@ -476,14 +326,12 @@ export const LeagueProviders: Provider[] = [
protestRepo: IProtestRepository,
driverRepo: IDriverRepository,
leagueRepo: ILeagueRepository,
output: GetLeagueProtestsPresenter,
) => new GetLeagueProtestsUseCase(raceRepo, protestRepo, driverRepo, leagueRepo, output),
) => new GetLeagueProtestsUseCase(raceRepo, protestRepo, driverRepo, leagueRepo),
inject: [
RACE_REPOSITORY_TOKEN,
PROTEST_REPOSITORY_TOKEN,
DRIVER_REPOSITORY_TOKEN,
LEAGUE_REPOSITORY_TOKEN,
GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN,
],
},
{
@@ -496,9 +344,8 @@ export const LeagueProviders: Provider[] = [
membershipRepo: ILeagueMembershipRepository,
driverRepo: IDriverRepository,
leagueRepo: ILeagueRepository,
output: GetLeagueMembershipsPresenter,
) => new GetLeagueMembershipsUseCase(membershipRepo, driverRepo, leagueRepo, output),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN, GetLeagueMembershipsPresenter],
) => new GetLeagueMembershipsUseCase(membershipRepo, driverRepo, leagueRepo),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, DRIVER_REPOSITORY_TOKEN, LEAGUE_REPOSITORY_TOKEN],
},
{
provide: GET_LEAGUE_ROSTER_MEMBERS_USE_CASE,
@@ -506,13 +353,11 @@ export const LeagueProviders: Provider[] = [
membershipRepo: ILeagueMembershipRepository,
driverRepo: IDriverRepository,
leagueRepo: ILeagueRepository,
output: GetLeagueRosterMembersPresenter,
) => new GetLeagueRosterMembersUseCase(membershipRepo, driverRepo, leagueRepo, output),
) => new GetLeagueRosterMembersUseCase(membershipRepo, driverRepo, leagueRepo),
inject: [
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
DRIVER_REPOSITORY_TOKEN,
LEAGUE_REPOSITORY_TOKEN,
GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN,
],
},
{
@@ -521,13 +366,11 @@ export const LeagueProviders: Provider[] = [
membershipRepo: ILeagueMembershipRepository,
driverRepo: IDriverRepository,
leagueRepo: ILeagueRepository,
output: GetLeagueRosterJoinRequestsPresenter,
) => new GetLeagueRosterJoinRequestsUseCase(membershipRepo, driverRepo, leagueRepo, output),
) => new GetLeagueRosterJoinRequestsUseCase(membershipRepo, driverRepo, leagueRepo),
inject: [
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
DRIVER_REPOSITORY_TOKEN,
LEAGUE_REPOSITORY_TOKEN,
GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN,
],
},
{
@@ -537,14 +380,12 @@ export const LeagueProviders: Provider[] = [
seasonRepo: ISeasonRepository,
raceRepo: IRaceRepository,
logger: Logger,
output: LeagueSchedulePresenter,
) => new GetLeagueScheduleUseCase(leagueRepo, seasonRepo, raceRepo, logger, output),
) => new GetLeagueScheduleUseCase(leagueRepo, seasonRepo, raceRepo, logger),
inject: [
LEAGUE_REPOSITORY_TOKEN,
SEASON_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
LOGGER_TOKEN,
GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN,
],
},
{
@@ -553,13 +394,11 @@ export const LeagueProviders: Provider[] = [
leagueRepo: ILeagueRepository,
leagueMembershipRepo: ILeagueMembershipRepository,
logger: Logger,
output: GetLeagueAdminPermissionsPresenter,
) => new GetLeagueAdminPermissionsUseCase(leagueRepo, leagueMembershipRepo, logger, output),
) => new GetLeagueAdminPermissionsUseCase(leagueRepo, leagueMembershipRepo, logger),
inject: [
LEAGUE_REPOSITORY_TOKEN,
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
LOGGER_TOKEN,
GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN,
],
},
{
@@ -568,13 +407,11 @@ export const LeagueProviders: Provider[] = [
leagueRepo: ILeagueRepository,
walletRepo: ILeagueWalletRepository,
transactionRepo: ITransactionRepository,
output: GetLeagueWalletPresenter,
) => new GetLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo, output),
) => new GetLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo),
inject: [
LEAGUE_REPOSITORY_TOKEN,
LEAGUE_WALLET_REPOSITORY_TOKEN,
TRANSACTION_REPOSITORY_TOKEN,
GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
],
},
{
@@ -584,14 +421,12 @@ export const LeagueProviders: Provider[] = [
walletRepo: ILeagueWalletRepository,
transactionRepo: ITransactionRepository,
logger: Logger,
output: WithdrawFromLeagueWalletPresenter,
) => new WithdrawFromLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo, logger, output),
) => new WithdrawFromLeagueWalletUseCase(leagueRepo, walletRepo, transactionRepo, logger),
inject: [
LEAGUE_REPOSITORY_TOKEN,
LEAGUE_WALLET_REPOSITORY_TOKEN,
TRANSACTION_REPOSITORY_TOKEN,
LOGGER_TOKEN,
WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN,
],
},
{
@@ -602,7 +437,6 @@ export const LeagueProviders: Provider[] = [
leagueRepo: ILeagueRepository,
leagueMembershipRepo: ILeagueMembershipRepository,
raceRepo: IRaceRepository,
output: GetSeasonSponsorshipsPresenter,
) =>
new GetSeasonSponsorshipsUseCase(
seasonSponsorshipRepo,
@@ -610,7 +444,6 @@ export const LeagueProviders: Provider[] = [
leagueRepo,
leagueMembershipRepo,
raceRepo,
output,
),
inject: [
'ISeasonSponsorshipRepository',
@@ -618,23 +451,21 @@ export const LeagueProviders: Provider[] = [
LEAGUE_REPOSITORY_TOKEN,
LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN,
],
},
{ // TODO wtf is this here? doesn't look like it adhers to our concepts
provide: LIST_LEAGUE_SCORING_PRESETS_USE_CASE,
useFactory: (output: LeagueScoringPresetsPresenter) =>
new ListLeagueScoringPresetsUseCase(listLeagueScoringPresets(), output),
inject: [LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN],
useFactory: () =>
new ListLeagueScoringPresetsUseCase(listLeagueScoringPresets()),
inject: [],
},
{
provide: JOIN_LEAGUE_USE_CASE,
useFactory: (
membershipRepo: ILeagueMembershipRepository,
logger: Logger,
output: JoinLeaguePresenter,
) => new JoinLeagueUseCase(membershipRepo, logger, output),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, LOGGER_TOKEN, JoinLeaguePresenter],
) => new JoinLeagueUseCase(membershipRepo, logger),
inject: [LEAGUE_MEMBERSHIP_REPOSITORY_TOKEN, LOGGER_TOKEN],
},
{
provide: TRANSFER_LEAGUE_OWNERSHIP_USE_CASE,
@@ -652,16 +483,14 @@ export const LeagueProviders: Provider[] = [
seasonRepo: ISeasonRepository,
raceRepo: IRaceRepository,
logger: Logger,
output: CreateLeagueSeasonScheduleRacePresenter,
) =>
new CreateLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger, output, {
new CreateLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger, {
generateRaceId: () => `race-${randomUUID()}`,
}),
inject: [
SEASON_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
LOGGER_TOKEN,
LeagueTokens.CREATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
],
},
{
@@ -670,13 +499,11 @@ export const LeagueProviders: Provider[] = [
seasonRepo: ISeasonRepository,
raceRepo: IRaceRepository,
logger: Logger,
output: UpdateLeagueSeasonScheduleRacePresenter,
) => new UpdateLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger, output),
) => new UpdateLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger),
inject: [
SEASON_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
LOGGER_TOKEN,
LeagueTokens.UPDATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
],
},
{
@@ -685,13 +512,11 @@ export const LeagueProviders: Provider[] = [
seasonRepo: ISeasonRepository,
raceRepo: IRaceRepository,
logger: Logger,
output: DeleteLeagueSeasonScheduleRacePresenter,
) => new DeleteLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger, output),
) => new DeleteLeagueSeasonScheduleRaceUseCase(seasonRepo, raceRepo, logger),
inject: [
SEASON_REPOSITORY_TOKEN,
RACE_REPOSITORY_TOKEN,
LOGGER_TOKEN,
LeagueTokens.DELETE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN,
],
},
{
@@ -699,12 +524,10 @@ export const LeagueProviders: Provider[] = [
useFactory: (
seasonRepo: ISeasonRepository,
logger: Logger,
output: PublishLeagueSeasonSchedulePresenter,
) => new PublishLeagueSeasonScheduleUseCase(seasonRepo, logger, output),
) => new PublishLeagueSeasonScheduleUseCase(seasonRepo, logger),
inject: [
SEASON_REPOSITORY_TOKEN,
LOGGER_TOKEN,
LeagueTokens.PUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN,
],
},
{
@@ -712,12 +535,10 @@ export const LeagueProviders: Provider[] = [
useFactory: (
seasonRepo: ISeasonRepository,
logger: Logger,
output: UnpublishLeagueSeasonSchedulePresenter,
) => new UnpublishLeagueSeasonScheduleUseCase(seasonRepo, logger, output),
) => new UnpublishLeagueSeasonScheduleUseCase(seasonRepo, logger),
inject: [
SEASON_REPOSITORY_TOKEN,
LOGGER_TOKEN,
LeagueTokens.UNPUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN,
],
},
];

View File

@@ -62,15 +62,19 @@ describe('LeagueService', () => {
present: vi.fn(),
getViewModel: vi.fn(() => ({ leagues: [], totalCount: 0 })),
};
const leagueStandingsPresenter = { getResponseModel: vi.fn(() => ({ standings: [] })) };
const leagueProtestsPresenter = { getResponseModel: vi.fn(() => ({ protests: [] })) };
const seasonSponsorshipsPresenter = { getViewModel: vi.fn(() => ({ sponsorships: [] })) };
const leagueScoringPresetsPresenter = { getViewModel: vi.fn(() => ({ presets: [] })) };
const approveLeagueJoinRequestPresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const createLeaguePresenter = { getViewModel: vi.fn(() => ({ id: 'l1' })) };
const getLeagueAdminPermissionsPresenter = { getResponseModel: vi.fn(() => ({ canManage: true })) };
const leagueStandingsPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ standings: [] })) };
const leagueProtestsPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ protests: [] })) };
const seasonSponsorshipsPresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ sponsorships: [] })) };
const leagueScoringPresetsPresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ presets: [] })) };
const approveLeagueJoinRequestPresenter = {
present: vi.fn(),
getViewModel: vi.fn(() => ({ success: true }))
};
const createLeaguePresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ id: 'l1' })) };
const getLeagueAdminPermissionsPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ canManage: true })) };
const getLeagueMembershipsPresenter = {
reset: vi.fn(),
present: vi.fn(),
getViewModel: vi.fn(() => ({ memberships: { memberships: [] } })),
};
@@ -85,27 +89,30 @@ describe('LeagueService', () => {
present: vi.fn(),
getViewModel: vi.fn(() => ([])),
};
const getLeagueOwnerSummaryPresenter = { getViewModel: vi.fn(() => ({ ownerId: 'o1' })) };
const getLeagueSeasonsPresenter = { getResponseModel: vi.fn(() => ([])) };
const joinLeaguePresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const leagueSchedulePresenter = { getViewModel: vi.fn(() => ({ seasonId: 'season-1', published: false, races: [] })) };
const leagueStatsPresenter = { getResponseModel: vi.fn(() => ({ stats: {} })) };
const rejectLeagueJoinRequestPresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const removeLeagueMemberPresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const totalLeaguesPresenter = { getResponseModel: vi.fn(() => ({ total: 1 })) };
const transferLeagueOwnershipPresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const updateLeagueMemberRolePresenter = { getViewModel: vi.fn(() => ({ success: true })) };
const getLeagueOwnerSummaryPresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ ownerId: 'o1' })) };
const getLeagueSeasonsPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ([])) };
const joinLeaguePresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ success: true })) };
const leagueSchedulePresenter = { reset: vi.fn(), present: vi.fn(), getViewModel: vi.fn(() => ({ seasonId: 'season-1', published: false, races: [] })) };
const leagueStatsPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ stats: {} })) };
const rejectLeagueJoinRequestPresenter = {
present: vi.fn(),
getViewModel: vi.fn(() => ({ success: true }))
};
const removeLeagueMemberPresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ success: true })) };
const totalLeaguesPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ total: 1 })) };
const transferLeagueOwnershipPresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ success: true })) };
const updateLeagueMemberRolePresenter = { present: vi.fn(), getViewModel: vi.fn(() => ({ success: true })) };
const leagueConfigPresenter = { getViewModel: vi.fn(() => ({ form: {} })) };
const leagueScoringConfigPresenter = { getViewModel: vi.fn(() => ({ config: {} })) };
const getLeagueWalletPresenter = { getResponseModel: vi.fn(() => ({ balance: 0 })) };
const withdrawFromLeagueWalletPresenter = { getResponseModel: vi.fn(() => ({ success: true })) };
const leagueJoinRequestsPresenter = { getViewModel: vi.fn(() => ({ joinRequests: [] })) };
const getLeagueWalletPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ balance: 0 })) };
const withdrawFromLeagueWalletPresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ success: true })) };
const leagueJoinRequestsPresenter = { reset: vi.fn(), present: vi.fn(), getViewModel: vi.fn(() => ({ joinRequests: [] })) };
const createLeagueSeasonScheduleRacePresenter = { getResponseModel: vi.fn(() => ({ raceId: 'race-1' })) };
const updateLeagueSeasonScheduleRacePresenter = { getResponseModel: vi.fn(() => ({ success: true })) };
const deleteLeagueSeasonScheduleRacePresenter = { getResponseModel: vi.fn(() => ({ success: true })) };
const publishLeagueSeasonSchedulePresenter = { getResponseModel: vi.fn(() => ({ success: true, published: true })) };
const unpublishLeagueSeasonSchedulePresenter = { getResponseModel: vi.fn(() => ({ success: true, published: false })) };
const createLeagueSeasonScheduleRacePresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ raceId: 'race-1' })) };
const updateLeagueSeasonScheduleRacePresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ success: true })) };
const deleteLeagueSeasonScheduleRacePresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ success: true })) };
const publishLeagueSeasonSchedulePresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ success: true, published: true })) };
const unpublishLeagueSeasonSchedulePresenter = { present: vi.fn(), getResponseModel: vi.fn(() => ({ success: true, published: false })) };
const service = new (LeagueService as any)(
getAllLeaguesWithCapacityUseCase as any,
@@ -195,8 +202,7 @@ describe('LeagueService', () => {
});
expect(rejectLeagueJoinRequestUseCase.execute).toHaveBeenCalledWith(
{ leagueId: 'l1', joinRequestId: 'r1' },
rejectLeagueJoinRequestPresenter,
{ leagueId: 'l1', joinRequestId: 'r1' }
);
await withUserId('user-1', async () => {

View File

@@ -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();
}
}

View File

@@ -48,37 +48,3 @@ export const UPDATE_LEAGUE_SEASON_SCHEDULE_RACE_USE_CASE = 'UpdateLeagueSeasonSc
export const DELETE_LEAGUE_SEASON_SCHEDULE_RACE_USE_CASE = 'DeleteLeagueSeasonScheduleRaceUseCase';
export const PUBLISH_LEAGUE_SEASON_SCHEDULE_USE_CASE = 'PublishLeagueSeasonScheduleUseCase';
export const UNPUBLISH_LEAGUE_SEASON_SCHEDULE_USE_CASE = 'UnpublishLeagueSeasonScheduleUseCase';
export const GET_ALL_LEAGUES_WITH_CAPACITY_OUTPUT_PORT_TOKEN = 'GetAllLeaguesWithCapacityOutputPort_TOKEN';
export const GET_ALL_LEAGUES_WITH_CAPACITY_AND_SCORING_OUTPUT_PORT_TOKEN = 'GetAllLeaguesWithCapacityAndScoringOutputPort_TOKEN';
export const GET_LEAGUE_STANDINGS_OUTPUT_PORT_TOKEN = 'GetLeagueStandingsOutputPort_TOKEN';
export const GET_LEAGUE_PROTESTS_OUTPUT_PORT_TOKEN = 'GetLeagueProtestsOutputPort_TOKEN';
export const GET_SEASON_SPONSORSHIPS_OUTPUT_PORT_TOKEN = 'GetSeasonSponsorshipsOutputPort_TOKEN';
export const LIST_LEAGUE_SCORING_PRESETS_OUTPUT_PORT_TOKEN = 'ListLeagueScoringPresetsOutputPort_TOKEN';
export const APPROVE_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'ApproveLeagueJoinRequestOutputPort_TOKEN';
export const CREATE_LEAGUE_OUTPUT_PORT_TOKEN = 'CreateLeagueOutputPort_TOKEN';
export const GET_LEAGUE_ADMIN_PERMISSIONS_OUTPUT_PORT_TOKEN = 'GetLeagueAdminPermissionsOutputPort_TOKEN';
export const GET_LEAGUE_MEMBERSHIPS_OUTPUT_PORT_TOKEN = 'GetLeagueMembershipsOutputPort_TOKEN';
export const GET_LEAGUE_ROSTER_MEMBERS_OUTPUT_PORT_TOKEN = 'GetLeagueRosterMembersOutputPort_TOKEN';
export const GET_LEAGUE_ROSTER_JOIN_REQUESTS_OUTPUT_PORT_TOKEN = 'GetLeagueRosterJoinRequestsOutputPort_TOKEN';
export const GET_LEAGUE_OWNER_SUMMARY_OUTPUT_PORT_TOKEN = 'GetLeagueOwnerSummaryOutputPort_TOKEN';
export const GET_LEAGUE_SEASONS_OUTPUT_PORT_TOKEN = 'GetLeagueSeasonsOutputPort_TOKEN';
export const JOIN_LEAGUE_OUTPUT_PORT_TOKEN = 'JoinLeagueOutputPort_TOKEN';
export const GET_LEAGUE_SCHEDULE_OUTPUT_PORT_TOKEN = 'GetLeagueScheduleOutputPort_TOKEN';
export const GET_LEAGUE_STATS_OUTPUT_PORT_TOKEN = 'GetLeagueStatsOutputPort_TOKEN';
export const REJECT_LEAGUE_JOIN_REQUEST_OUTPUT_PORT_TOKEN = 'RejectLeagueJoinRequestOutputPort_TOKEN';
export const REMOVE_LEAGUE_MEMBER_OUTPUT_PORT_TOKEN = 'RemoveLeagueMemberOutputPort_TOKEN';
export const TOTAL_LEAGUES_OUTPUT_PORT_TOKEN = 'TotalLeaguesOutputPort_TOKEN';
export const TRANSFER_LEAGUE_OWNERSHIP_OUTPUT_PORT_TOKEN = 'TransferLeagueOwnershipOutputPort_TOKEN';
export const UPDATE_LEAGUE_MEMBER_ROLE_OUTPUT_PORT_TOKEN = 'UpdateLeagueMemberRoleOutputPort_TOKEN';
export const GET_LEAGUE_FULL_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueFullConfigOutputPort_TOKEN';
export const GET_LEAGUE_SCORING_CONFIG_OUTPUT_PORT_TOKEN = 'GetLeagueScoringConfigOutputPort_TOKEN';
export const GET_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'GetLeagueWalletOutputPort_TOKEN';
export const WITHDRAW_FROM_LEAGUE_WALLET_OUTPUT_PORT_TOKEN = 'WithdrawFromLeagueWalletOutputPort_TOKEN';
// Schedule mutation output ports
export const CREATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN = 'CreateLeagueSeasonScheduleRaceOutputPort_TOKEN';
export const UPDATE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN = 'UpdateLeagueSeasonScheduleRaceOutputPort_TOKEN';
export const DELETE_LEAGUE_SEASON_SCHEDULE_RACE_OUTPUT_PORT_TOKEN = 'DeleteLeagueSeasonScheduleRaceOutputPort_TOKEN';
export const PUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN = 'PublishLeagueSeasonScheduleOutputPort_TOKEN';
export const UNPUBLISH_LEAGUE_SEASON_SCHEDULE_OUTPUT_PORT_TOKEN = 'UnpublishLeagueSeasonScheduleOutputPort_TOKEN';

View File

@@ -17,6 +17,8 @@ describe('LeagueOwnerSummaryPresenter', () => {
joinedAt: { toDate: () => new Date('2024-01-01T00:00:00Z') } as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
totalMembers: 50,
activeMembers: 45,
rating: 1500,
rank: 100,
};

View File

@@ -1,3 +1,4 @@
import { Injectable } from '@nestjs/common';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { GetLeagueRosterMembersResult } from '@core/racing/application/use-cases/GetLeagueRosterMembersUseCase';
import type { GetLeagueRosterJoinRequestsResult } from '@core/racing/application/use-cases/GetLeagueRosterJoinRequestsUseCase';
@@ -5,6 +6,7 @@ import type { LeagueRosterMemberDTO } from '../dtos/LeagueRosterMemberDTO';
import type { LeagueRosterJoinRequestDTO } from '../dtos/LeagueRosterJoinRequestDTO';
import type { DriverDTO } from '../../driver/dtos/DriverDTO';
@Injectable()
export class GetLeagueRosterMembersPresenter implements UseCaseOutputPort<GetLeagueRosterMembersResult> {
private viewModel: LeagueRosterMemberDTO[] | null = null;
@@ -37,6 +39,7 @@ export class GetLeagueRosterMembersPresenter implements UseCaseOutputPort<GetLea
}
}
@Injectable()
export class GetLeagueRosterJoinRequestsPresenter implements UseCaseOutputPort<GetLeagueRosterJoinRequestsResult> {
private viewModel: LeagueRosterJoinRequestDTO[] | null = null;