@@ -6,7 +6,7 @@ import { Loader } from './loader.js';
6
6
7
7
export class DasiaEnglishLoader implements Loader {
8
8
getLoaderName ( ) : string {
9
- return 'anthonymays ' ;
9
+ return 'dasiaenglish ' ;
10
10
}
11
11
12
12
async loadData ( ) : Promise < MediaItem [ ] > {
@@ -21,17 +21,18 @@ export class DasiaEnglishLoader implements Loader {
21
21
}
22
22
23
23
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
+
33
34
// 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
35
36
}
36
37
37
38
async loadCredits ( ) : Promise < Credit [ ] > {
@@ -41,7 +42,7 @@ export class DasiaEnglishLoader implements Loader {
41
42
. pipe ( csv ( ) ) ;
42
43
for await ( const row of readable ) {
43
44
const { media_item_id : mediaItemId , role, name } = row ;
44
- credits . push ( { mediaItemId, name, role } ) ;
45
+ credits . push ( new Credit ( mediaItemId , name , role ) ) ;
45
46
}
46
47
return credits ;
47
48
}
0 commit comments