website refactor
This commit is contained in:
48
apps/website/lib/services/teams/TeamJoinService.ts
Normal file
48
apps/website/lib/services/teams/TeamJoinService.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { TeamsApiClient } from '@/lib/api/teams/TeamsApiClient';
|
||||
import { TeamJoinRequestViewModel } from '@/lib/view-models/TeamJoinRequestViewModel';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
|
||||
/**
|
||||
* Team Join Service - ViewModels
|
||||
*
|
||||
* Returns ViewModels for team join requests.
|
||||
* Handles presentation logic for join request management.
|
||||
*/
|
||||
export class TeamJoinService implements Service {
|
||||
private apiClient: TeamsApiClient;
|
||||
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger, {
|
||||
showUserNotifications: true,
|
||||
logToConsole: true,
|
||||
reportToExternal: process.env.NODE_ENV === 'production',
|
||||
});
|
||||
this.apiClient = new TeamsApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
|
||||
async getJoinRequests(teamId: string, currentDriverId: string, isOwner: boolean): Promise<TeamJoinRequestViewModel[]> {
|
||||
try {
|
||||
const result = await this.apiClient.getJoinRequests(teamId);
|
||||
return result.requests.map(request =>
|
||||
new TeamJoinRequestViewModel(request, currentDriverId, isOwner)
|
||||
);
|
||||
} catch (error) {
|
||||
// Return empty array on error
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async approveJoinRequest(): Promise<void> {
|
||||
throw new Error('Not implemented: API endpoint for approving join requests');
|
||||
}
|
||||
|
||||
async rejectJoinRequest(): Promise<void> {
|
||||
throw new Error('Not implemented: API endpoint for rejecting join requests');
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,79 @@
|
||||
import { TeamsApiClient } from '@/lib/api/teams/TeamsApiClient';
|
||||
import { TeamSummaryViewModel } from '@/lib/view-models/TeamSummaryViewModel';
|
||||
import { TeamMemberViewModel } from '@/lib/view-models/TeamMemberViewModel';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
|
||||
/**
|
||||
* Team Service - DTO Only
|
||||
*
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
* All client-side presentation logic must be handled by hooks/components.
|
||||
*/
|
||||
export class TeamService {
|
||||
constructor(private readonly apiClient: any) {}
|
||||
export class TeamService implements Service {
|
||||
private apiClient: TeamsApiClient;
|
||||
|
||||
async getTeamById(teamId: string): Promise<any> {
|
||||
return { id: teamId, name: 'Team' };
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger, {
|
||||
showUserNotifications: true,
|
||||
logToConsole: true,
|
||||
reportToExternal: process.env.NODE_ENV === 'production',
|
||||
});
|
||||
this.apiClient = new TeamsApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
|
||||
async getTeamsByLeagueId(leagueId: string): Promise<any> {
|
||||
return { teams: [] };
|
||||
async getAllTeams(): Promise<Result<TeamSummaryViewModel[], DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getAll();
|
||||
return Result.ok(result.teams.map(team => new TeamSummaryViewModel(team)));
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'unknown', message: 'Failed to fetch teams' });
|
||||
}
|
||||
}
|
||||
|
||||
async getTeamDetails(_teamId: string, _currentDriverId: string): Promise<Result<any, DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getDetails(_teamId);
|
||||
if (!result) {
|
||||
return Result.err({ type: 'notFound', message: 'Team not found' });
|
||||
}
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'unknown', message: 'Failed to fetch team details' });
|
||||
}
|
||||
}
|
||||
|
||||
async getTeamMembers(teamId: string, currentDriverId: string, ownerId: string): Promise<Result<TeamMemberViewModel[], DomainError>> {
|
||||
try {
|
||||
const result = await this.apiClient.getMembers(teamId);
|
||||
return Result.ok(result.members.map(member => new TeamMemberViewModel(member, currentDriverId, ownerId)));
|
||||
} catch (error) {
|
||||
return Result.err({ type: 'unknown', message: 'Failed to fetch team members' });
|
||||
}
|
||||
}
|
||||
|
||||
async getTeamJoinRequests(_teamId: string): Promise<Result<any, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'getTeamJoinRequests' });
|
||||
}
|
||||
|
||||
async createTeam(_input: any): Promise<Result<any, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'createTeam' });
|
||||
}
|
||||
|
||||
async updateTeam(_teamId: string, _input: any): Promise<Result<any, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'updateTeam' });
|
||||
}
|
||||
|
||||
async getDriverTeam(_driverId: string): Promise<Result<any, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'getDriverTeam' });
|
||||
}
|
||||
|
||||
async getMembership(_teamId: string, _driverId: string): Promise<Result<any, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'getMembership' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user