wip
This commit is contained in:
52
packages/social/application/use-cases/GetUserFeedUseCase.ts
Normal file
52
packages/social/application/use-cases/GetUserFeedUseCase.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user