add helper functions for order and process object transformations
This commit is contained in:
@@ -1,4 +1,126 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
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;
|
||||||
|
|||||||
19
frontend/src/helpers/ProcessHelper.js
Normal file
19
frontend/src/helpers/ProcessHelper.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import moment from "moment";
|
||||||
|
|
||||||
|
export const fromWiaasProcessStep = (step) => {
|
||||||
|
return {
|
||||||
|
actionCode: step.action_code,
|
||||||
|
actualDate: step.actual_date,
|
||||||
|
comments: step.comments,
|
||||||
|
fullDesc: step.full_desc,
|
||||||
|
idOrder: step.order_id,
|
||||||
|
idProcess: step.step_form_entry_id, //not sure about this
|
||||||
|
idProcessStep: step.step_id, //not sure about this
|
||||||
|
isNewCommentVisible: 1, //TODO : get this from backend
|
||||||
|
isVisibleForCustomer: 1, //TODO : get this from backend
|
||||||
|
now: moment().format("Do MMM YY"),
|
||||||
|
shortDesc: step.short_desc,
|
||||||
|
status: step.status,
|
||||||
|
stepType: step.step_type,
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user