49 lines
2.0 KiB
TypeScript
49 lines
2.0 KiB
TypeScript
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';
|
|
import { isProductionEnvironment } from '@/lib/config/env';
|
|
|
|
/**
|
|
* 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: isProductionEnvironment(),
|
|
});
|
|
this.apiClient = new TeamsApiClient(baseUrl, errorReporter, logger);
|
|
}
|
|
|
|
async getJoinRequests(teamId: string, currentDriverId: string, isOwner: boolean): Promise<Result<TeamJoinRequestViewModel[], DomainError>> {
|
|
try {
|
|
const result = await this.apiClient.getJoinRequests(teamId);
|
|
return Result.ok(result.requests.map(request =>
|
|
new TeamJoinRequestViewModel(request, currentDriverId, isOwner)
|
|
));
|
|
} catch (error: any) {
|
|
return Result.err({ type: 'serverError', message: error.message || 'Failed to fetch join requests' });
|
|
}
|
|
}
|
|
|
|
async approveJoinRequest(): Promise<Result<void, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'Not implemented: API endpoint for approving join requests' });
|
|
}
|
|
|
|
async rejectJoinRequest(): Promise<Result<void, DomainError>> {
|
|
return Result.err({ type: 'notImplemented', message: 'Not implemented: API endpoint for rejecting join requests' });
|
|
}
|
|
}
|