Created
July 1, 2020 15:23
-
-
Save Miczeq22/84014024ff0d3f93f057c7427771c924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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