or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

ObjectId Request Handling

A minimal HTTP module that enforces MongoDB ObjectId validation and parsing on incoming request data using the dependency's built-in pipes.

Capabilities

Validate path parameters without conversion

  • GET /customers/:customerId responds with status 200 and JSON { "id": "<customerId>" } when the path segment is a valid ObjectId string; it responds with status 400 when the segment is not a valid ObjectId format. @test

Parse path parameters into ObjectId instances

  • DELETE /customers/:customerId/orders/:orderId uses the dependency's ObjectId-parsing pipe to convert both path segments before invoking the service, returning status 200 with { "deleted": true, "customer": "<ObjectId>", "order": "<ObjectId>" } when both are valid and 400 when either is invalid. @test

Handle optional ObjectId queries

  • GET /customers accepts the referrerId query parameter as optional: when omitted it returns status 200 with { "referrerId": null }; when provided as a valid ObjectId string it echoes that value; when provided but invalid it responds with status 400. @test

Implementation

@generates

API

export class CustomersController {
  constructor(service: CustomersService);

  /**
   * Returns the validated customer id string.
   */
  getCustomer(customerId: string): Promise<{ id: string }>;

  /**
   * Parses and forwards ObjectIds for deletion.
   */
  deleteOrder(
    customerId: import('mongoose').Types.ObjectId,
    orderId: import('mongoose').Types.ObjectId,
  ): Promise<{ deleted: true; customer: import('mongoose').Types.ObjectId; order: import('mongoose').Types.ObjectId }>;

  /**
   * Returns the optional referrer id string or null when absent.
   */
  listCustomers(referrerId: string | null): Promise<{ referrerId: string | null }>;
}

export class CustomersService {
  deleteOrder(
    customerId: import('mongoose').Types.ObjectId,
    orderId: import('mongoose').Types.ObjectId,
  ): Promise<{ deleted: true; customer: import('mongoose').Types.ObjectId; order: import('mongoose').Types.ObjectId }>;
}

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Provides built-in pipes for validating or parsing MongoDB ObjectId inputs in the NestJS request lifecycle.