Skip to content

Commit 24a0edc

Browse files
committed
fix: added an array as well as changing to a simplier code
1 parent 5ad4219 commit 24a0edc

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lesson_10/libraries/src/loaders/dasia_english_loader.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Loader } from './loader.js';
66

77
export class DasiaEnglishLoader implements Loader {
88
getLoaderName(): string {
9-
return 'anthonymays';
9+
return 'dasiaenglish';
1010
}
1111

1212
async loadData(): Promise<MediaItem[]> {
@@ -21,17 +21,18 @@ export class DasiaEnglishLoader implements Loader {
2121
}
2222

2323
async loadMediaItems(): Promise<MediaItem[]> {
24-
const matches = fs
25-
.readFileSync('data/media_items.csv', {
26-
encoding: 'utf-8',
27-
})
28-
.split('\n')
29-
.map((row: string): string[] => {
30-
return row.split(',');
31-
});
32-
console.log(matches);
24+
const media = [];
25+
const readable = fs
26+
.createReadStream('data/media_items.csv', 'utf-8')
27+
.pipe(csv());
28+
for await (const row of readable) {
29+
const { id, type, title, year } = row;
30+
media.push(new MediaItem(id, title, type, year, []));
31+
}
32+
return media;
33+
3334
// I used this youtube video to help me understand the above code: https://www.youtube.com/watch?v=bbvECy0ICuo
34-
return [];
35+
// I also got help from Lj on getting my test to run correctly
3536
}
3637

3738
async loadCredits(): Promise<Credit[]> {
@@ -41,7 +42,7 @@ export class DasiaEnglishLoader implements Loader {
4142
.pipe(csv());
4243
for await (const row of readable) {
4344
const { media_item_id: mediaItemId, role, name } = row;
44-
credits.push({ mediaItemId, name, role });
45+
credits.push(new Credit(mediaItemId, name, role));
4546
}
4647
return credits;
4748
}

0 commit comments

Comments
 (0)