website refactor
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { injectable, unmanaged } from 'inversify';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { AuthService } from './AuthService';
|
||||
@@ -10,25 +11,26 @@ import { SessionViewModel } from '@/lib/view-models/SessionViewModel';
|
||||
* Orchestrates session-related operations.
|
||||
* Returns raw API DTOs. No ViewModels or UX logic.
|
||||
*/
|
||||
@injectable()
|
||||
export class SessionService implements Service {
|
||||
private authService: AuthService;
|
||||
|
||||
constructor(apiClient?: any) {
|
||||
constructor(@unmanaged() apiClient?: any) {
|
||||
this.authService = new AuthService(apiClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user session
|
||||
*/
|
||||
async getSession(): Promise<any> {
|
||||
async getSession(): Promise<Result<SessionViewModel | null, DomainError>> {
|
||||
try {
|
||||
const res = await this.authService.getSession();
|
||||
if (!res) return null;
|
||||
if (!res) return Result.ok(null);
|
||||
const data = (res as any).value || res;
|
||||
if (!data || !data.user) return null;
|
||||
return new SessionViewModel(data.user);
|
||||
if (!data || !data.user) return Result.ok(null);
|
||||
return Result.ok(new SessionViewModel(data.user));
|
||||
} catch (error: unknown) {
|
||||
throw error;
|
||||
return Result.err({ type: 'serverError', message: (error as Error).message || 'Failed to get session' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user