remove hardcoded values and change comment handling
This commit is contained in:
@@ -1,127 +1,6 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {fromWiaasProcessStep} from './ProcessHelper';
|
import {fromWiaasProcessStep} from './ProcessHelper';
|
||||||
|
|
||||||
const tempTransformationFunction = (order) => {
|
|
||||||
let processInfo = Object.assign({},order['delivery-process']);
|
|
||||||
if (order['delivery-process']){
|
|
||||||
processInfo.steps = order['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
let processInfo = Object.assign({},order['delivery-process']);
|
|
||||||
processInfo.steps = order['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
|
|
||||||
/*
|
|
||||||
processInfo[order['delivery-process'].id] = {
|
|
||||||
idProcess: order['delivery-process'].id,
|
|
||||||
processName: order['delivery-process'].name,
|
|
||||||
steps: order['delivery-process'].steps.map(step => {
|
|
||||||
return transformProcessStep(step, order['delivery-process'].id);
|
|
||||||
})
|
|
||||||
}*/
|
|
||||||
|
|
||||||
let TransformedPackagesArray = order.line_items.map(packageItem => {
|
|
||||||
return {
|
|
||||||
endOfLife: null,
|
|
||||||
units: packageItem.quantity,
|
|
||||||
packageFixedPrice: packageItem.price,
|
|
||||||
packageRecurringPrice: 0,
|
|
||||||
packageServicePrice: 0,
|
|
||||||
status: 'no-process',
|
|
||||||
packagePayPeriod: 0,
|
|
||||||
servicesContractPeriod: 0,
|
|
||||||
maxContractPeriod: 0,
|
|
||||||
periodUnit: 'months',
|
|
||||||
paymentType: 'Managed service 36M rent',
|
|
||||||
idOrder: order.id,
|
|
||||||
idPackage: packageItem.id,
|
|
||||||
packageName: packageItem.name,
|
|
||||||
packageCurrency: {
|
|
||||||
currency: order.currency
|
|
||||||
},
|
|
||||||
documents: [{
|
|
||||||
idDocument: 1,
|
|
||||||
documentName: 'customerQuestionaire_343_32_2',
|
|
||||||
documentPath: 'path/to/document/withExtension.docx',
|
|
||||||
extension: 'docx',
|
|
||||||
documentType: 'Order Questionaire',
|
|
||||||
documentTypeName: 'orderQuestionarie',
|
|
||||||
idPackage: packageItem.id
|
|
||||||
}],
|
|
||||||
options: [],
|
|
||||||
additionalPackages: [],
|
|
||||||
idOrderPackagePair: `${order.id}-${packageItem.id}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//going through same array again - for cleaner code
|
|
||||||
let newProductsObject = {};
|
|
||||||
order.line_items.forEach(element => {
|
|
||||||
newProductsObject[element.id] = {
|
|
||||||
software: [{
|
|
||||||
productName: 'Software product',
|
|
||||||
category: 'software',
|
|
||||||
idPackage: element.id
|
|
||||||
}],
|
|
||||||
hardware: [{
|
|
||||||
productName: 'Hardware product',
|
|
||||||
category: 'hardware',
|
|
||||||
idPackage: element.id
|
|
||||||
}],
|
|
||||||
service: [{
|
|
||||||
productName: 'Service product',
|
|
||||||
category: 'service',
|
|
||||||
idPackage: element.id
|
|
||||||
}],
|
|
||||||
installation: [{
|
|
||||||
productName: 'Installation product',
|
|
||||||
category: 'installation',
|
|
||||||
idPackage: element.id
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let comments = [];
|
|
||||||
let processID = null;
|
|
||||||
order.meta_data.forEach(element => {
|
|
||||||
if (element.key.substring(0, 7) === 'comment') {
|
|
||||||
comments.push(element.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
info: {
|
|
||||||
id: order.id,
|
|
||||||
orderNumber: order.number,
|
|
||||||
orderDate: moment(order.date_created).format("Do MMM, YYYY"),
|
|
||||||
estimatedDeliveryDate: null,
|
|
||||||
billingFirstName: order.billing.first_name,
|
|
||||||
billingLastName: order.billing.last_name,
|
|
||||||
billingMail: order.billing.email,
|
|
||||||
billingAddress: order.billing.address_1 + ' ' + order.billing.address_2,
|
|
||||||
status: order.status,
|
|
||||||
reference: 'reference field',
|
|
||||||
tender: 'tender field',
|
|
||||||
idTerms: null,
|
|
||||||
idProject: null,
|
|
||||||
projectName: 'project name field',
|
|
||||||
assignedTo: 'assigned to',
|
|
||||||
customer: 'customer field',
|
|
||||||
phone: null,
|
|
||||||
mail: '',
|
|
||||||
idCommercialLead: null,
|
|
||||||
commercialLead: '',
|
|
||||||
endOfLife: null,
|
|
||||||
idProcess: processID,
|
|
||||||
},
|
|
||||||
products: newProductsObject,
|
|
||||||
packages: TransformedPackagesArray,
|
|
||||||
process: processInfo,
|
|
||||||
orderDocuments: [],
|
|
||||||
selections: [],
|
|
||||||
orderComments: comments,
|
|
||||||
availableProcesses: [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
||||||
}
|
}
|
||||||
@@ -130,7 +9,18 @@ function formatAddress(addressObject) {
|
|||||||
return `${addressObject.address_1}, ${addressObject.city}, ${addressObject.country}, ${addressObject.postcode}`;
|
return `${addressObject.address_1}, ${addressObject.city}, ${addressObject.country}, ${addressObject.postcode}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractComments(metaDataArray){
|
||||||
|
const commentsObject = metaDataArray.find(metaDataElement => {
|
||||||
|
return metaDataElement.key === "comments";
|
||||||
|
});
|
||||||
|
return commentsObject ? JSON.parse(commentsObject.value) : [];
|
||||||
|
}
|
||||||
|
|
||||||
export const fromWCOrder = (WCOrder) => {
|
export const fromWCOrder = (WCOrder) => {
|
||||||
|
let processInfo = Object.assign({},WCOrder['delivery-process']);
|
||||||
|
if (WCOrder['delivery-process']){
|
||||||
|
processInfo.steps = WCOrder['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
id: WCOrder.id,
|
id: WCOrder.id,
|
||||||
number: WCOrder.number,
|
number: WCOrder.number,
|
||||||
@@ -144,6 +34,12 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
recurringPrice: 0,
|
recurringPrice: 0,
|
||||||
status: WCOrder.status,
|
status: WCOrder.status,
|
||||||
currency: WCOrder.currency,
|
currency: WCOrder.currency,
|
||||||
|
billing:{
|
||||||
|
firstName: WCOrder.billing.first_name,
|
||||||
|
lastName: WCOrder.billing.last_name,
|
||||||
|
email: WCOrder.billing.email,
|
||||||
|
address: formatAddress(WCOrder.billing)
|
||||||
|
},
|
||||||
packages: WCOrder['line_items'].map(packageLine => {
|
packages: WCOrder['line_items'].map(packageLine => {
|
||||||
return {
|
return {
|
||||||
id: packageLine['product_id'],
|
id: packageLine['product_id'],
|
||||||
@@ -162,6 +58,8 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
dateCompleted: formatDate(packageLine['date_completed']),
|
dateCompleted: formatDate(packageLine['date_completed']),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
process: processInfo,
|
||||||
|
comments: extractComments(WCOrder.meta_data),
|
||||||
deliveryAddress: formatAddress(WCOrder.shipping),
|
deliveryAddress: formatAddress(WCOrder.shipping),
|
||||||
customer: WCOrder.customer,
|
customer: WCOrder.customer,
|
||||||
commercialLead: WCOrder['commercial_lead']
|
commercialLead: WCOrder['commercial_lead']
|
||||||
|
|||||||
Reference in New Issue
Block a user