or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Polymorphic Media Catalog

Build a small persistence layer that stores multiple media variants in a single collection using discriminator schemas so child-specific fields are preserved while sharing base fields.

Capabilities

  • Creating both article and video records stores them under one base collection while keeping variant-only fields and a kind discriminator value for each saved document. @test
  • Retrieving all media returns both variants with their discriminator-specific fields intact and a base createdAt timestamp. @test
  • Querying by title returns the correct variant with its discriminator-specific shape; unknown titles resolve to null. @test
  • Clearing the catalog removes every variant from the shared collection so tests can start from an empty state. @test

Implementation

@generates

API

export type MediaKind = 'article' | 'video';

export interface MediaInput {
  title: string;
}

export interface ArticleInput extends MediaInput {
  author: string;
  wordCount: number;
}

export interface VideoInput extends MediaInput {
  durationSeconds: number;
  resolution: '720p' | '1080p' | '4k';
}

export type MediaRecord =
  | ({ _id: string; kind: 'article'; createdAt: Date } & ArticleInput)
  | ({ _id: string; kind: 'video'; createdAt: Date } & VideoInput);

export class MediaService {
  constructor(uri?: string);
  clear(): Promise<void>;
  addArticle(input: ArticleInput): Promise<MediaRecord>;
  addVideo(input: VideoInput): Promise<MediaRecord>;
  listMedia(): Promise<MediaRecord[]>;
  findByTitle(title: string): Promise<MediaRecord | null>;
  close(): Promise<void>;
}

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Integrates MongoDB schemas and discriminator models into NestJS applications.