Skip to content

Commit aeba25b

Browse files
committed
Feat/Have 2 tests pass but still have 1 skipped
1 parent b01aa8a commit aeba25b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import csv from 'csv-parser';
2+
import fs from 'fs';
3+
import { Credit, MediaItem } from '../models/index.js';
4+
5+
export class DylanLaffertysLoader {
6+
getLoaderName() {
7+
return 'dylanlafferty';
8+
}
9+
async loadData(): Promise<MediaItem[]> {
10+
const credits = await this.loadCredits();
11+
const mediaItems = await this.loadMediaItems();
12+
console.log(
13+
`Loaded ${credits.length} credits and ${mediaItems.length} media items`,
14+
);
15+
return [...mediaItems.values()];
16+
}
17+
18+
async loadMediaItems(): Promise<MediaItem[]> {
19+
const mediaItem = [];
20+
const readable = fs
21+
.createReadStream('data/media_items.csv', 'utf-8')
22+
.pipe(csv());
23+
24+
for await (const row of readable) {
25+
const { id, title, type, releaseYear } = row;
26+
mediaItem.push(new MediaItem(id, title, type, parseInt(releaseYear), []));
27+
}
28+
return mediaItem;
29+
}
30+
31+
async loadCredits(): Promise<Credit[]> {
32+
const credits = [];
33+
const readable = fs
34+
.createReadStream('data/credits.csv', 'utf-8')
35+
.pipe(csv());
36+
for await (const row of readable) {
37+
const { media_item_id, role, name } = row;
38+
credits.push(new Credit(media_item_id, name, role));
39+
}
40+
return credits;
41+
}
42+
}
43+
//# sourceMappingURL=dylan_lafferty_loaders.js.map

lesson_10/libraries/src/loaders/loaders.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Module } from '@nestjs/common';
22

33
import { AnthonyMaysLoader } from './anthony_mays_loader.js';
4+
import { DylanLaffertysLoader } from './dylan_lafferty_loaders.js';
45

56
export const Loaders = Symbol.for('Loaders');
67

7-
const LOADER_PROVIDERS = [AnthonyMaysLoader];
8+
const LOADER_PROVIDERS = [AnthonyMaysLoader, DylanLaffertysLoader];
89

910
@Module({
1011
providers: [

0 commit comments

Comments
 (0)