or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Product Catalog Schema Builder

Defines decorated classes for a product catalog and produces both a runtime schema and a raw definition that align with MongoDB via the dependency's class-to-schema utilities.

Capabilities

Generates schema for product fields

  • Schema exposes required string path for name and required number path for price, and applies default value 0 for inventoryCount when saving a product missing that field. @test

Maps nested category, tags, and dimensions

  • Schema stores category as nested object with required title and slug, persists tags as an array of strings, and treats dimensions as optional nested object with numeric width and height fields. @test

Adds computed virtual

  • Schema includes a virtual fullTitle that returns "<name> - <category.title>" and appears in JSON output when virtuals are enabled, while remaining non-persisted. @test

Exposes raw definition

  • Raw schema definition export matches the product shape (required name/price, string tags array, nested category, optional dimensions, defaulted inventoryCount) so async model registration can reuse it without re-describing fields. @test

Implementation

@generates

API

export class Dimensions {
  width: number;
  height: number;
}

export class Category {
  title: string;
  slug: string;
}

export class Product {
  name: string;
  price: number;
  tags: string[];
  category: Category;
  dimensions?: Dimensions;
  inventoryCount?: number;
  fullTitle: string;
}

export function buildProductSchema(): import('mongoose').Schema;
export function buildProductDefinition(): Record<string, any>;

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Provides decorators and factory helpers to turn decorated classes into schemas and raw definitions compatible with NestJS and Mongoose.