Skip to content

Commit

Permalink
Feat: Fixed two files for lesson 10 by Hummad Tanweer (#348)
Browse files Browse the repository at this point in the history
* Feat: Fixed two files for lesson 10 by Hummad Tanweer

* resloved conflicts

* changes to loader file

* Feat: Fixed two files for lesson 10 by Hummad Tanweer

* resloved conflicts

* changes to loader file

---------

Co-authored-by: Anthony D. Mays <[email protected]>
  • Loading branch information
htanweer244 and anthonydmays authored Oct 23, 2024
1 parent a1bc9f7 commit 8cc7e02
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
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

0 comments on commit 8cc7e02

Please sign in to comment.