module creation
This commit is contained in:
125
apps/api/src/modules/league/LeagueService.ts
Normal file
125
apps/api/src/modules/league/LeagueService.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AllLeaguesWithCapacityViewModel, LeagueStatsDto, LeagueJoinRequestViewModel, ApproveJoinRequestInput, ApproveJoinRequestOutput, RejectJoinRequestInput, RejectJoinRequestOutput, LeagueAdminPermissionsViewModel, RemoveLeagueMemberInput, RemoveLeagueMemberOutput, UpdateLeagueMemberRoleInput, UpdateLeagueMemberRoleOutput, LeagueOwnerSummaryViewModel, LeagueConfigFormModelDto, LeagueAdminProtestsViewModel, LeagueSeasonSummaryViewModel, GetLeagueAdminPermissionsInput, GetLeagueJoinRequestsQuery, GetLeagueProtestsQuery, GetLeagueSeasonsQuery, GetLeagueAdminConfigQuery, GetLeagueOwnerSummaryQuery } from './dto/LeagueDto';
|
||||
import { DriverDto } from '../driver/dto/DriverDto'; // Using the local DTO for mock data
|
||||
import { RaceDto } from '../race/dto/RaceDto'; // Using the local DTO for mock data
|
||||
|
||||
const mockDriverData: Map<string, DriverDto> = new Map();
|
||||
mockDriverData.set('driver-owner-1', { id: 'driver-owner-1', name: 'Owner Driver' });
|
||||
mockDriverData.set('driver-1', { id: 'driver-1', name: 'Demo Driver 1' });
|
||||
mockDriverData.set('driver-2', { id: 'driver-2', name: 'Demo Driver 2' });
|
||||
|
||||
const mockRaceData: Map<string, RaceDto> = new Map();
|
||||
mockRaceData.set('race-1', { id: 'race-1', name: 'Test Race 1', date: new Date().toISOString() });
|
||||
mockRaceData.set('race-2', { id: 'race-2', name: 'Test Race 2', date: new Date().toISOString() });
|
||||
|
||||
@Injectable()
|
||||
export class LeagueService {
|
||||
|
||||
constructor() {}
|
||||
|
||||
async getAllLeaguesWithCapacity(): Promise<AllLeaguesWithCapacityViewModel> {
|
||||
console.log('[LeagueService] Returning mock leagues with capacity.');
|
||||
return {
|
||||
leagues: [
|
||||
{ id: 'league-1', name: 'Global Racing', description: 'The premier league', ownerId: 'owner-1', settings: { maxDrivers: 100 }, createdAt: new Date().toISOString(), usedSlots: 50, socialLinks: { discordUrl: 'https://discord.gg/test' } },
|
||||
{ id: 'league-2', name: 'Amateur Series', description: 'Learn the ropes', ownerId: 'owner-2', settings: { maxDrivers: 50 }, createdAt: new Date().toISOString(), usedSlots: 20 },
|
||||
],
|
||||
totalCount: 2,
|
||||
};
|
||||
}
|
||||
|
||||
async getTotalLeagues(): Promise<LeagueStatsDto> {
|
||||
console.log('[LeagueService] Returning mock total leagues.');
|
||||
return { totalLeagues: 2 };
|
||||
}
|
||||
|
||||
async getLeagueJoinRequests(leagueId: string): Promise<LeagueJoinRequestViewModel[]> {
|
||||
console.log(`[LeagueService] Returning mock join requests for league: ${leagueId}.`);
|
||||
return [
|
||||
{
|
||||
id: 'join-req-1',
|
||||
leagueId: 'league-1',
|
||||
driverId: 'driver-1',
|
||||
requestedAt: new Date(),
|
||||
message: 'I want to join!',
|
||||
driver: mockDriverData.get('driver-1'),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
async approveLeagueJoinRequest(input: ApproveJoinRequestInput): Promise<ApproveJoinRequestOutput> {
|
||||
console.log('Approving join request:', input);
|
||||
return { success: true, message: 'Join request approved.' };
|
||||
}
|
||||
|
||||
async rejectLeagueJoinRequest(input: RejectJoinRequestInput): Promise<RejectJoinRequestOutput> {
|
||||
console.log('Rejecting join request:', input);
|
||||
return { success: true, message: 'Join request rejected.' };
|
||||
}
|
||||
|
||||
async getLeagueAdminPermissions(query: GetLeagueAdminPermissionsInput): Promise<LeagueAdminPermissionsViewModel> {
|
||||
console.log('Getting league admin permissions:', query);
|
||||
return { canRemoveMember: true, canUpdateRoles: true };
|
||||
}
|
||||
|
||||
async removeLeagueMember(input: RemoveLeagueMemberInput): Promise<RemoveLeagueMemberOutput> {
|
||||
console.log('Removing league member:', input.leagueId, input.targetDriverId);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
async updateLeagueMemberRole(input: UpdateLeagueMemberRoleInput): Promise<UpdateLeagueMemberRoleOutput> {
|
||||
console.log('Updating league member role:', input.leagueId, input.targetDriverId, input.newRole);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
async getLeagueOwnerSummary(query: GetLeagueOwnerSummaryQuery): Promise<LeagueOwnerSummaryViewModel | null> {
|
||||
console.log('Getting league owner summary:', query);
|
||||
return {
|
||||
driver: mockDriverData.get(query.ownerId)!,
|
||||
rating: 2000,
|
||||
rank: 1,
|
||||
};
|
||||
}
|
||||
|
||||
async getLeagueFullConfig(query: GetLeagueAdminConfigQuery): Promise<LeagueConfigFormModelDto | null> {
|
||||
console.log('Getting league full config:', query);
|
||||
return {
|
||||
leagueId: 'league-1',
|
||||
basics: { name: 'Demo League', description: 'A demo league', visibility: 'public' },
|
||||
structure: { mode: 'solo' },
|
||||
championships: [],
|
||||
scoring: { type: 'standard', points: 10 },
|
||||
dropPolicy: { strategy: 'none' },
|
||||
timings: { raceDayOfWeek: 'Sunday', raceTimeHour: 20, raceTimeMinute: 0 },
|
||||
stewarding: {
|
||||
decisionMode: 'single_steward',
|
||||
requireDefense: false,
|
||||
defenseTimeLimit: 24,
|
||||
voteTimeLimit: 24,
|
||||
protestDeadlineHours: 2,
|
||||
stewardingClosesHours: 24,
|
||||
notifyAccusedOnProtest: true,
|
||||
notifyOnVoteRequired: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async getLeagueProtests(query: GetLeagueProtestsQuery): Promise<LeagueAdminProtestsViewModel> {
|
||||
console.log('Getting league protests:', query);
|
||||
return {
|
||||
protests: [
|
||||
{ id: 'protest-1', raceId: 'race-1', protestingDriverId: 'driver-1', accusedDriverId: 'driver-2', submittedAt: new Date(), description: 'Bad driving!', status: 'pending' },
|
||||
],
|
||||
racesById: { 'race-1': mockRaceData.get('race-1')! },
|
||||
driversById: { 'driver-1': mockDriverData.get('driver-1')!, 'driver-2': mockDriverData.get('driver-2')! },
|
||||
};
|
||||
}
|
||||
|
||||
async getLeagueSeasons(query: GetLeagueSeasonsQuery): Promise<LeagueSeasonSummaryViewModel[]> {
|
||||
console.log('Getting league seasons:', query);
|
||||
return [
|
||||
{ seasonId: 'season-1', name: 'Season 1', status: 'active', startDate: new Date('2025-01-01'), endDate: new Date('2025-12-31'), isPrimary: true, isParallelActive: false },
|
||||
{ seasonId: 'season-2', name: 'Season 2', status: 'upcoming', startDate: new Date('2026-01-01'), endDate: new Date('2026-12-31'), isPrimary: false, isParallelActive: false },
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user