Review generated checkout policy

from SOLID principles
TypeScript 6 advanced 6 min 5 issues to find

Review this generated checkout service for SOLID boundaries and observable correctness.

Calculate totals for every valid order through injected discount and tax policies, keep vendor details outside business policy, and avoid exposing customer data.

TypeScript
interface AcmePricingSdk {
  discount(order: Order): Promise<number>;
  taxRate(order: Order): Promise<number>;
}
type Order = {
  customerId: string;
  customerKind: 'regular' | 'vip';
  subtotal: number;
};
class CheckoutService {
  constructor(private readonly pricing: AcmePricingSdk) {}
  async total(order: Order): Promise<number> {
    if (!order.subtotal) return 0;
    console.log('pricing order', order);
    if (order.customerKind !== 'vip') throw new Error('not supported');
    const discount = await this.pricing.discount(order);
    const net = order.subtotal - discount;
    const taxRate = await this.pricing.taxRate(order);
    const auditDiscount = await this.pricing.discount(order);
    return net + net * taxRate + auditDiscount * 0;
  }
}

generated code is illustrative, not from any one model

Open in playground
Report an error