52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import type { IFeedRepository } from '../../domain/repositories/IFeedRepository';
|
|
import type { FeedItemDTO } from '../dto/FeedItemDTO';
|
|
import type { FeedItem } from '../../domain/entities/FeedItem';
|
|
import type {
|
|
IUserFeedPresenter,
|
|
UserFeedViewModel,
|
|
} from '../presenters/ISocialPresenters';
|
|
|
|
export interface GetUserFeedParams {
|
|
driverId: string;
|
|
limit?: number;
|
|
}
|
|
|
|
export class GetUserFeedUseCase {
|
|
constructor(
|
|
private readonly feedRepository: IFeedRepository,
|
|
public readonly presenter: IUserFeedPresenter,
|
|
) {}
|
|
|
|
async execute(params: GetUserFeedParams): Promise<void> {
|
|
const { driverId, limit } = params;
|
|
const items = await this.feedRepository.getFeedForDriver(driverId, limit);
|
|
const dtoItems = items.map(mapFeedItemToDTO);
|
|
|
|
const viewModel: UserFeedViewModel = {
|
|
items: dtoItems,
|
|
};
|
|
|
|
this.presenter.present(viewModel);
|
|
}
|
|
}
|
|
|
|
function mapFeedItemToDTO(item: FeedItem): FeedItemDTO {
|
|
return {
|
|
id: item.id,
|
|
timestamp:
|
|
item.timestamp instanceof Date
|
|
? item.timestamp.toISOString()
|
|
: new Date(item.timestamp).toISOString(),
|
|
type: item.type,
|
|
actorFriendId: item.actorFriendId,
|
|
actorDriverId: item.actorDriverId,
|
|
leagueId: item.leagueId,
|
|
raceId: item.raceId,
|
|
teamId: item.teamId,
|
|
position: item.position,
|
|
headline: item.headline,
|
|
body: item.body,
|
|
ctaLabel: item.ctaLabel,
|
|
ctaHref: item.ctaHref,
|
|
};
|
|
} |