Files
gridpilot.gg/apps/website/lib/services/teams/TeamJoinService.ts

48 lines
1.8 KiB
TypeScript

import { TeamJoinRequestViewModel, type TeamJoinRequestDTO } from '@/lib/view-models/TeamJoinRequestViewModel';
import type { TeamsApiClient } from '../../api/teams/TeamsApiClient';
// Wrapper for the team join requests collection returned by the teams API in this build
// Mirrors the current API response shape until a generated DTO is available.
type TeamJoinRequestsDto = {
requests: TeamJoinRequestDTO[];
};
/**
* Team Join Service
*
* Orchestrates team join/leave operations by coordinating API calls and view model creation.
* All dependencies are injected via constructor.
*/
export class TeamJoinService {
constructor(
private readonly apiClient: TeamsApiClient
) {}
/**
* Get team join requests with view model transformation
*/
async getJoinRequests(teamId: string, currentUserId: string, isOwner: boolean): Promise<TeamJoinRequestViewModel[]> {
const dto = await this.apiClient.getJoinRequests(teamId) as TeamJoinRequestsDto;
return dto.requests.map((r: TeamJoinRequestDTO) => new TeamJoinRequestViewModel(r, currentUserId, isOwner));
}
/**
* Approve a team join request
*
* The teams API currently exposes read-only join requests in this build; approving
* a request requires a future management endpoint, so this method fails explicitly.
*/
async approveJoinRequest(): Promise<never> {
throw new Error('Approving team join requests is not supported in this build');
}
/**
* Reject a team join request
*
* Rejection of join requests is also not available yet on the backend, so callers
* must treat this as an unsupported operation rather than a silent no-op.
*/
async rejectJoinRequest(): Promise<never> {
throw new Error('Rejecting team join requests is not supported in this build');
}
}