Skip to content

Instantly share code, notes, and snippets.

@Miczeq22
Created July 1, 2020 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miczeq22/84014024ff0d3f93f057c7427771c924 to your computer and use it in GitHub Desktop.
Save Miczeq22/84014024ff0d3f93f057c7427771c924 to your computer and use it in GitHub Desktop.
interface GetUserEnrolledDecksQueryHandlerDependencies {
enrolledDeckRepository: EnrolledDeckRepository;
deckElasticView: ElasticView<Deck>;
storageClient: StorageClient;
}
export class GetUserEnrolledDecksQueryHandler extends QueryHandler<
GetUserEnrolledDecks,
GetUserEnrolledDecksQueryResult
> {
constructor(
private readonly dependencies: GetUserEnrolledDecksQueryHandlerDependencies,
) {
super(GET_USER_ENROLLED_DECKS_QUERY_TYPE);
}
public async execute({ payload: { userId } }: GetUserEnrolledDecks) {
const {
enrolledDeckRepository,
deckElasticView,
storageClient,
} = this.dependencies;
const enrolledDecks = await enrolledDeckRepository.getAllByUser(userId);
const { items } = await deckElasticView.findMany({
ids: enrolledDecks.map(enrolledDeck => enrolledDeck.getDeckId()),
});
return new GetUserEnrolledDecksQueryResult(
items.map(item => ({
...item,
imgUrl: item.imgUrl
? storageClient.getPublicUrlResolver(item.imgUrl)
: '',
})),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment