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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | 29x 29x 29x 29x 29x 29x 29x 6x 6x 6x 6x 1x 1x 1x 1x 1x | import { AddressMapper } from 'ish-core/models/address/address.mapper';
import { AttributeHelper } from 'ish-core/models/attribute/attribute.helper';
import { BasketMapper } from 'ish-core/models/basket/basket.mapper';
import { LineItemMapper } from 'ish-core/models/line-item/line-item.mapper';
import { PagingInfo } from 'ish-core/models/paging-info/paging-info.model';
import { PaymentMapper } from 'ish-core/models/payment/payment.mapper';
import { ShippingMethodMapper } from 'ish-core/models/shipping-method/shipping-method.mapper';
import { OrderData } from './order.interface';
import { Order, Orders } from './order.model';
export class OrderMapper {
// eslint-disable-next-line complexity
static fromData(payload: OrderData): Order {
if (!Array.isArray(payload.data)) {
const { data, included, infos } = payload;
const totals = BasketMapper.getTotals(data, included ? included.discounts : undefined);
return {
id: data.id,
documentNo: data.documentNumber,
creationDate: data.creationDate,
orderCreation: data.orderCreation,
statusCode: data.statusCode,
status: data.status,
requisitionNo: data.requisitionDocumentNo,
recurringOrderID: data.recurringOrderID,
approval:
data.attributes &&
AttributeHelper.getAttributeValueByAttributeName(
data.attributes,
'BusinessObjectAttributes#OrderApproval_ApprovalDate'
)
? {
date: AttributeHelper.getAttributeValueByAttributeName(
data.attributes,
'BusinessObjectAttributes#OrderApproval_ApprovalDate'
),
approverFirstName: AttributeHelper.getAttributeValueByAttributeName(
data.attributes,
'BusinessObjectAttributes#OrderApproval_ApproverFirstName'
),
approverLastName: AttributeHelper.getAttributeValueByAttributeName(
data.attributes,
'BusinessObjectAttributes#OrderApproval_ApproverLastName'
),
}
: undefined,
purchaseCurrency: data.purchaseCurrency,
dynamicMessages: data.discounts ? data.discounts.dynamicMessages : undefined,
invoiceToAddress:
included?.invoiceToAddress && data.invoiceToAddress
? AddressMapper.fromData(included.invoiceToAddress[data.invoiceToAddress])
: undefined,
commonShipToAddress:
included?.commonShipToAddress && data.commonShipToAddress
? AddressMapper.fromData(included.commonShipToAddress[data.commonShipToAddress])
: undefined,
commonShippingMethod:
included?.commonShippingMethod && data.commonShippingMethod
? ShippingMethodMapper.fromData(included.commonShippingMethod[data.commonShippingMethod])
: undefined,
costCenter: data.costCenter,
customerNo: data.customer,
email: data.user,
lineItems:
included?.lineItems && data.lineItems?.length
? data.lineItems.map(lineItemId =>
LineItemMapper.fromOrderItemData(
included.lineItems[lineItemId],
included.lineItems_discounts,
included.lineItems_warranty
)
)
: [],
totalProductQuantity: data.totalProductQuantity,
payment:
included?.payments && data.payments?.length && included.payments[data.payments[0]]
? PaymentMapper.fromIncludeData(
included.payments[data.payments[0]],
included.payments_paymentMethod?.[included.payments[data.payments[0]].paymentMethod]
? included.payments_paymentMethod[included.payments[data.payments[0]].paymentMethod]
: undefined,
included.payments[data.payments[0]].paymentInstrument && included.payments_paymentInstrument
? included.payments_paymentInstrument[included.payments[data.payments[0]].paymentInstrument]
: undefined
)
: undefined,
totals,
infos,
attributes: data.attributes,
taxationId: data.taxIdentificationNumber,
user: data.buyer,
messageToMerchant: data.messageToMerchant,
externalOrderReference: data.externalOrderReference,
};
}
}
static fromListData(payload: OrderData): Orders {
Iif (Array.isArray(payload.data)) {
return {
orders: payload.data.map(data => OrderMapper.fromData({ ...payload, data })),
paging: OrderMapper.fromInfo(payload),
};
}
}
static fromInfo(payload: OrderData): PagingInfo {
if (payload.info) {
const { info } = payload;
return {
limit: info.limit,
offset: info.offset,
total: info.total,
};
}
}
}
|