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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | 27x 27x 27x 27x 27x 27x 5x 4x 4x 4x 1x 3x 1x 1x 1x 1x | import { Injectable } from '@angular/core';
import { BasketBaseData } from 'ish-core/models/basket/basket.interface';
import { BasketMapper } from 'ish-core/models/basket/basket.mapper';
import { CustomFieldMapper } from 'ish-core/models/custom-field/custom-field.mapper';
import { LineItemMapper } from 'ish-core/models/line-item/line-item.mapper';
import { PaymentMapper } from 'ish-core/models/payment/payment.mapper';
import { RecurringOrderData, RecurringOrderListData } from './recurring-order.interface';
import { RecurringOrder } from './recurring-order.model';
@Injectable({ providedIn: 'root' })
export class RecurringOrderMapper {
static fromListData(recurringOrdersData: RecurringOrderListData[]): RecurringOrder[] {
Iif (!recurringOrdersData.length) {
return [];
}
return recurringOrdersData.map(data => ({
id: data.id,
documentNo: data.number,
active: data.active,
expired: data.expired,
recurrence: {
interval: data.interval,
startDate: data.startDate,
endDate: data.endDate,
repetitions: data.repetitions,
},
creationDate: data.creationDate,
lastOrderDate: data.lastOrderDate,
nextOrderDate: data.nextOrderDate,
customerNo: data.buyer?.customerNo,
email: data.buyer?.email,
user: {
email: data.buyer?.email,
firstName: data.buyer?.firstName,
lastName: data.buyer?.lastName,
companyName: data.buyer?.companyName,
},
totals: {
total: {
type: 'PriceItem',
gross: data.totalGross.amount,
net: data.totalNet.amount,
currency: data.totalGross.currency,
},
// required properties for 'totals'
itemTotal: undefined,
isEstimated: false,
},
}));
}
static fromData(payload: RecurringOrderData): RecurringOrder {
const { data, included } = payload;
if (!data) {
return;
}
return {
id: data.id,
documentNo: data.number,
active: data.active,
expired: data.expired,
error: data.error,
errorCode: data.errorCode,
statusCode: data.statusCode,
recurrence: {
interval: data.interval,
startDate: data.startDate,
endDate: data.endDate,
repetitions: data.repetitions,
},
creationDate: data.creationDate,
lastOrderDate: data.lastOrderDate,
nextOrderDate: data.nextOrderDate,
orderCount: data.orderCount,
costCenter: data.costCenterID,
costCenterName: data.costCenterName,
customerNo: data.buyer?.customerNo,
email: data.buyer?.email,
user: {
email: data.buyer?.email,
firstName: data.buyer?.firstName,
lastName: data.buyer?.lastName,
companyName: data.buyer?.companyName,
},
invoiceToAddress: data.addresses?.find(address => address.urn === data.invoiceToAddress),
commonShipToAddress: data.addresses?.find(address => address.urn === data.shippingBuckets?.[0]?.shipToAddress),
commonShippingMethod: data.shippingMethods?.find(
methods => methods.id === data.shippingBuckets?.[0]?.shippingMethod
),
payment: data.payments?.length
? PaymentMapper.fromIncludeData(data.payments[0], data.paymentMethods[0], undefined)
: undefined,
approvalStatuses: data.approvalStatuses
?.map(status => ({
approvalDate: status.approvalDate,
approver: status.approver,
statusCode: status.statusCode,
}))
.filter(
(value, index, self) =>
index ===
self.findIndex(
t =>
t.approvalDate === value.approvalDate &&
t.approver.firstName === value.approver.firstName &&
t.approver.lastName === value.approver.lastName
)
),
lastPlacedOrders: data.lastOrders,
lineItems: data.lineItems?.length
? data.lineItems.map(lineItem =>
LineItemMapper.fromData(lineItem, included?.lineItems_discounts, included?.lineItems_warranty)
)
: [],
customFields: CustomFieldMapper.fromData(data.customFields),
totals: BasketMapper.getTotals(data as unknown as BasketBaseData, included ? included.discounts : undefined),
};
}
}
|