35 lines
987 B
TypeScript
35 lines
987 B
TypeScript
import { Result } from '@/lib/contracts/Result';
|
|
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
|
import { AuthService } from './AuthService';
|
|
import type { AuthSessionDTO } from '@/lib/types/generated/AuthSessionDTO';
|
|
import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
|
|
|
/**
|
|
* Session Service
|
|
*
|
|
* Orchestrates session-related operations.
|
|
* Returns raw API DTOs. No ViewModels or UX logic.
|
|
*/
|
|
export class SessionService implements Service {
|
|
private authService: AuthService;
|
|
|
|
constructor(apiClient?: any) {
|
|
this.authService = new AuthService(apiClient);
|
|
}
|
|
|
|
/**
|
|
* Get current user session
|
|
*/
|
|
async getSession(): Promise<any> {
|
|
try {
|
|
const res = await this.authService.getSession();
|
|
if (!res) return null;
|
|
const data = (res as any).value || res;
|
|
if (!data || !data.user) return null;
|
|
return new SessionViewModel(data.user);
|
|
} catch (error: unknown) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|