All files / src/entities discount.ts

68% Statements 17/25
0% Branches 0/5
50% Functions 1/2
68.18% Lines 15/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x   1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x                         1x  
import { Entity } from '../entity.js';
import { DiscountGroup } from './discount_group.js';
 
export class Discount extends Entity {
  protected static resourceName = 'discounts';
  protected static singularName = 'discount';
  protected static pluralName = 'discounts';
 
  @Discount.property({type: Date})
  public archived?: Date | null;
 
  @Discount.property()
  public id?: number;
 
  @Discount.property()
  public lowerLimit?: number;
 
  @Discount.property()
  public amount?: number;
 
  @Discount.property()
  public usageLimit?: number;
 
  @Discount.property()
  public isPercentage?: boolean;
 
  @Discount.property()
  public code?: string;
 
  @Discount.property({type: DiscountGroup})
  public discountGroup?: DiscountGroup | null;
 
  public discountedUnitCost = (unitPrice: number | undefined) => {
    Iif (unitPrice === undefined) {
      throw 'unitPrice is undefined, did you forget to embed it?';
    }
    Iif (this.amount === undefined) {
      throw 'amount is undefined, did you forget to embed it?';
    }
    const discount = 100 - this.amount;
    return (unitPrice * discount / 100).toFixed(3);
  };
}