Files
gridpilot.gg/packages/social/application/use-cases/GetCurrentUserSocialUseCase.ts
2025-12-12 14:23:40 +01:00

54 lines
1.6 KiB
TypeScript

import type { AsyncUseCase } from '@gridpilot/shared/application';
import type { ISocialGraphRepository } from '../../domain/repositories/ISocialGraphRepository';
import type { CurrentUserSocialDTO } from '../dto/CurrentUserSocialDTO';
import type { FriendDTO } from '../dto/FriendDTO';
import type {
CurrentUserSocialViewModel,
ICurrentUserSocialPresenter,
} from '../presenters/ISocialPresenters';
export interface GetCurrentUserSocialParams {
driverId: string;
}
/**
* Application-level use case to retrieve the current user's social context.
*
* Keeps orchestration in the social bounded context while delegating
* data access to domain repositories and presenting via a presenter.
*/
export class GetCurrentUserSocialUseCase
implements AsyncUseCase<GetCurrentUserSocialParams, void> {
constructor(
private readonly socialGraphRepository: ISocialGraphRepository,
public readonly presenter: ICurrentUserSocialPresenter,
) {}
async execute(params: GetCurrentUserSocialParams): Promise<void> {
const { driverId } = params;
const friendsDomain = await this.socialGraphRepository.getFriends(driverId);
const friends: FriendDTO[] = friendsDomain.map((friend) => ({
driverId: friend.id,
displayName: friend.name,
avatarUrl: '',
isOnline: false,
lastSeen: new Date(),
}));
const currentUser: CurrentUserSocialDTO = {
driverId,
displayName: '',
avatarUrl: '',
countryCode: '',
};
const viewModel: CurrentUserSocialViewModel = {
currentUser,
friends,
};
this.presenter.present(viewModel);
}
}