Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Fixed two files for lesson 10 by Hummad Tanweer #348

Merged
merged 12 commits into from
Oct 23, 2024
45 changes: 45 additions & 0 deletions lesson_10/libraries/src/loaders/hummad_tanweer_loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class HummadTanweerLoader implements Loader {
getLoaderName(): string {
return 'hummadtanweer';
}

async loadData(): Promise<MediaItem[]> {
const credits = await this.loadCredits();
const mediaItems = await this.loadMediaItems();

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

return [...mediaItems.values()];
}

async loadMediaItems(): Promise<MediaItem[]> {
const media = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { id, title, type, year: realeaseYear } = row;
media.push(new MediaItem(id, title, type, realeaseYear, []));
}
return media;
}

async loadCredits(): Promise<Credit[]> {
const credits = [];
const readable = fs
.createReadStream('data/credits.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { media_item_id, role, name } = row;
credits.push(new Credit(media_item_id, name, role));
}
return credits;
}
}
6 changes: 5 additions & 1 deletion lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Module } from '@nestjs/common';

import { AngelicaCastilloLoader } from './angelica_castillo_loader.js';
import { HummadTanweerLoader } from './hummad_tanweer_loader.js';
import { AnthonyMaysLoader } from './anthony_mays_loader.js';
import { DavidSmithLoader } from './david_smith_loader.js';
import { DwightBlueLoader } from './dwight_blue_loader.js';
Expand All @@ -12,15 +14,17 @@ import { TommyTranLoader } from './tommy_tran_loader.js';
import { XavierCruzLoader } from './xavier_cruz_loader.js';
import { ZionBuchananLoader } from './zion_buchanan_loader.js';


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

// Add your quiz provider here.

const LOADER_PROVIDERS = [
AnthonyMaysLoader,
AngelicaCastilloLoader,
AnthonyMaysLoader,
DavidSmithLoader,
DwightBlueLoader,
HummadTanweerLoader,
JamesCapparellLoader,
JosephCaballeroLoader,
KimberleeHaldaneLoader,
Expand Down