website refactor
This commit is contained in:
@@ -16,33 +16,38 @@ import { isProductionEnvironment } from '@/lib/config/env';
|
||||
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' });
|
||||
constructor(apiClient?: TeamsApiClient) {
|
||||
if (apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
} else {
|
||||
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 approveJoinRequest(): Promise<Result<void, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'Not implemented: API endpoint for approving join requests' });
|
||||
async getJoinRequests(teamId: string, currentDriverId: string, isOwner: boolean): Promise<any[]> {
|
||||
try {
|
||||
const result = await this.apiClient.getJoinRequests(teamId);
|
||||
const requests = (result as any).requests || result;
|
||||
return requests.map((request: any) =>
|
||||
new TeamJoinRequestViewModel(request, currentDriverId, isOwner)
|
||||
);
|
||||
} catch (error: any) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async rejectJoinRequest(): Promise<Result<void, DomainError>> {
|
||||
return Result.err({ type: 'notImplemented', message: 'Not implemented: API endpoint for rejecting join requests' });
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user