Skip to content

feat: Lesson 10 credits / media items upload - created by Dwight Blue #340

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lesson_10/libraries/src/loaders/cdbluejr_loader.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file should be named dwight_blue_loader.ts

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import csv from 'csv-parser';
import fs from 'fs';
import { Credit, MediaItem } from '../models/index.js';
import { Loader } from './loader.js';

export class DwightBlueLoader implements Loader {
getLoaderName(): string {
return 'dwightblue';
}

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[]> {
// TODO: Implement this method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment.

const mediaItem = [];
const readable = fs
.createReadStream('data/media_items.csv', 'utf-8')
.pipe(csv());
for await (const row of readable) {
const { id, title, type, year } = row;
mediaItem.push(new MediaItem(id, title, type, year, []));
}
return mediaItem;
}

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: mediaItemId, role, name } = row;
credits.push(new Credit(mediaItemId, name, role));
}
return credits;
}
}
8 changes: 7 additions & 1 deletion lesson_10/libraries/src/loaders/loaders.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Module } from '@nestjs/common';
import { AnthonyMaysLoader } from './anthony_mays_loader.js';
import { DwightBlueLoader } from './cdbluejr_loader.js';
import { XavierCruzLoader } from './xavier_cruz_loader.js';

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

// Add your quiz provider here.
const LOADER_PROVIDERS = [AnthonyMaysLoader];
const LOADER_PROVIDERS = [
AnthonyMaysLoader,
DwightBlueLoader,
XavierCruzLoader,
];

@Module({
providers: [
Expand Down