All files / src/entities inventory.ts

79.31% Statements 23/29
0% Branches 0/4
33.33% Functions 1/3
80.76% Lines 21/26

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 641x 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 { Entity } from '../entity.js';
import { InventoryGroup } from './inventory_group.js';
import { InventoryUnitVariation } from './inventory_unit_variation.js';
import { Job } from './job.js';
import { Product } from './product.js';
import { VariationsGroup } from './variations_group.js';
import { VariationFieldsOption } from './variation_fields_option.js';
import { some } from 'lodash';
 
export class Inventory extends Entity {
  protected static resourceName = 'inventories';
  protected static singularName = 'inventory';
  protected static pluralName = 'inventories';
 
  @Inventory.property({type: Date})
  public archived?: Date | null;
 
  @Inventory.property()
  public id?: number;
 
  @Inventory.property()
  public quantity?: number;
 
  @Inventory.property()
  public name?: string;
 
  @Inventory.property()
  public position?: number;
 
  @Inventory.property()
  public notes?: string;
 
  @Inventory.property()
  public isOrphan?: boolean;
 
  @Inventory.property({arrayType: 'Product'})
  public products?: Product[];
 
  @Inventory.property({arrayType: 'InventoryGroup'})
  public inventoryGroups?: InventoryGroup[];
 
  @Inventory.property({type: Address})
  public address?: Address | null;
 
  @Inventory.property({arrayType: 'VariationsGroup'})
  public variationsGroups?: VariationsGroup[];
 
  @Inventory.property({arrayType: 'Job'})
  public jobs?: Job[];
 
  @Inventory.property({arrayType: 'InventoryUnitVariation'})
  public inventoryUnitVariations?: InventoryUnitVariation[];
 
  public isVariationFieldOptionSelected = (option: VariationFieldsOption) => {
    Iif (this.inventoryUnitVariations === undefined) {
      throw new Error(
        'inventoryUnitVariations is undefined, did you forget to embed it?');
    }
    return some(this.inventoryUnitVariations.map(
      (v: InventoryUnitVariation) => v.optionId() === option.id));
  };
}