Skip to content

Commit b12d5a3

Browse files
author
Ezra Nyabuti
committed
feat: enhance Ezra's loader to associate credits with media items
1 parent f70749f commit b12d5a3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lesson_10/libraries/src/loaders/ezra_nyabuti_loaders.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ export class EzraNyabutiLoaders implements Loader {
1111
async loadData(): Promise<MediaItem[]> {
1212
const credits = await this.loadCredits();
1313
const mediaItems = await this.loadMediaItems();
14+
const mediaMap = new Map<string, MediaItem>();
15+
mediaItems.forEach((mediaItem) =>
16+
mediaMap.set(mediaItem.getId(), mediaItem),
17+
);
18+
credits.forEach((credit) => {
19+
const mediaItem = mediaMap.get(credit.getMediaItemId());
20+
if (mediaItem) {
21+
mediaItem.addCredit(credit);
22+
}
23+
});
24+
for (const mediaItem of mediaItems) {
25+
console.log(mediaItem);
26+
}
1427

1528
console.log(
1629
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,

0 commit comments

Comments
 (0)