All files / src/app/core/models/address address.mapper.ts

75% Statements 3/4
62.5% Branches 10/16
100% Functions 1/1
75% Lines 3/4

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      37x   23x 23x                                                                                
import { AddressData } from './address.interface';
import { Address } from './address.model';
 
export class AddressMapper {
  static fromData(data: AddressData): Address {
    if (data) {
      return {
        id: data.id,
        urn: data.urn,
        type: data.type,
        addressName: data.addressName,
        companyName1: data.companyName1,
        companyName2: data.companyName2,
        title: data.title,
        firstName: data.firstName,
        lastName: data.lastName,
        addressLine1: data.addressLine1,
        addressLine2: data.addressLine2,
        addressLine3: data.addressLine3,
        postalCode: data.postalCode,
        city: data.city,
        mainDivision: data.mainDivisionName || data.mainDivision,
        mainDivisionCode: data.mainDivisionCode || data.mainDivision,
        country: data.country,
        countryCode: data.countryCode,
        phoneHome: data.phoneHome,
        phoneMobile: data.phoneMobile,
        phoneBusiness: data.phoneBusiness,
        phoneBusinessDirect: data.phoneBusinessDirect,
        fax: data.fax,
        email: data.email,
        invoiceToAddress:
          data.eligibleInvoiceToAddress !== undefined ? data.eligibleInvoiceToAddress : data.invoiceToAddress,
        shipToAddress: data.eligibleShipToAddress !== undefined ? data.eligibleShipToAddress : data.shipToAddress,
        shipFromAddress:
          data.eligibleShipFromAddress !== undefined ? data.eligibleShipFromAddress : data.shipFromAddress,
        serviceToAddress:
          data.eligibleServiceToAddress !== undefined ? data.eligibleServiceToAddress : data.serviceToAddress,
        installToAddress:
          data.eligibleInstallToAddress !== undefined ? data.eligibleInstallToAddress : data.installToAddress,
      };
    } else E{
      throw new Error(`'addressData' is required for the mapping`);
    }
  }
}