All files / src/entities cart.ts

76.08% Statements 35/46
0% Branches 0/5
50% Functions 1/2
82.5% Lines 33/40

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1001x     1x 1x 1x         1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                           1x  
import { Address } from './address.js';
import { CartItem } from './cart_item.js';
import { CartShipmentGroup } from './cart_shipment_group.js';
import { Company } from './company.js';
import { Domain } from './domain.js';
import { Entity } from '../entity.js';
import { Invoice } from './invoice.js';
import { User } from './user.js';
import { Item } from './item.js';
 
export class Cart extends Entity {
  protected static resourceName = 'carts';
  protected static singularName = 'cart';
  protected static pluralName = 'carts';
 
  @Cart.property({type: Date})
  public archived?: Date | null;
 
  @Cart.property()
  public id?: number;
 
  @Cart.property()
  public creationDate?: Date;
 
  @Cart.property()
  public updated?: Date;
 
  @Cart.property({type: Date})
  public ip?: string | null;
 
  @Cart.property({type: String})
  public token?: string | null;
 
  @Cart.property({type: String})
  public receiverNotes?: string | null;
 
  @Cart.property()
  public currency?: string;
 
  @Cart.property()
  public cartItemsSubtotalCost?: number;
 
  @Cart.property()
  public cartItemsTaxAmount?: number;
 
  @Cart.property()
  public cartItemsTotalCost?: number;
 
  @Cart.property()
  public shipmentTotalCost?: number;
 
  @Cart.property()
  public subtotalCost?: number;
 
  @Cart.property()
  public taxAmount?: number;
 
  @Cart.property()
  public totalCost?: number;
 
  @Cart.property()
  public sendWhatsapp?: boolean;
 
  @Cart.property({type: 'User'})
  public client?: User | null;
 
  @Cart.property({type: Company})
  public clientCompany?: Company | null;
 
  @Cart.property()
  public domain?: Domain;
 
  @Cart.property({type: 'Invoice'})
  public invoice?: Invoice | null;
 
  @Cart.property({type: Address})
  public receiverAddress?: Address | null;
 
  @Cart.property({arrayType: 'Item'})
  public discountItems?: Item[];
 
  @Cart.property({arrayType: 'CartItem'})
  public cartItems?: CartItem[];
 
  @Cart.property({arrayType: 'CartShipmentGroup'})
  public shipmentGroups?: CartShipmentGroup[];
 
  public requiresShipment = () => {
    Iif (this.cartItems === undefined) {
      throw 'cartItems is undefined, did you forget to embed it?';
    }
    for (const cartItem of this.cartItems) {
      Iif (cartItem.requiresShipment()) {
        return true;
      }
    }
    return false;
  };
}