or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-1/

Order Analytics Injection

Use dependency injection to persist orders and audit entries through injected database models and connections instead of constructing them manually.

Capabilities

Uses injected models and connection tokens

  • The service receives one order model bound to the default connection and one audit model bound to a named connection through the package's injection helpers; no manual model or connection construction is allowed. @test

Record order with audit trail

  • Given { customerId: "c-1", totalCents: 2500 }, recordOrder stores the order via the injected order model and writes an audit entry referencing the saved order id via the audit model; it returns both persisted records. @test

Transactional write support

  • When recordOrder is invoked with { customerId: "c-2", totalCents: 5000, useTransaction: true } and the audit write fails, both order and audit writes are rolled back using a session from the injected connection. @test

Fetch audit history

  • fetchAuditHistory(orderId) returns audit entries for that order, sorted most recent first, using the injected audit model tied to the named connection. @test

Implementation

@generates

API

export interface OrderPayload {
  customerId: string;
  totalCents: number;
  useTransaction?: boolean;
}

export interface OrderRecord {
  id: string;
  customerId: string;
  totalCents: number;
  createdAt: Date;
}

export interface AuditEntry {
  id: string;
  orderId: string;
  action: 'created';
  at: Date;
}

export class OrderAnalyticsService {
  constructor(/* injected models and a database connection */);

  recordOrder(order: OrderPayload): Promise<{ order: OrderRecord; audit: AuditEntry }>;

  fetchAuditHistory(orderId: string): Promise<AuditEntry[]>;
}

Dependencies { .dependencies }

@nestjs/mongoose { .dependency }

Provides framework-level integration for injecting database models and connections in NestJS providers. @satisfied-by