export class TrxMappingData { trackingStates: any = {}; /** * Sets the inital state of the mapped headers. * @param data Mapped header data. */ setInitialState(data: Array) { this.trackingStates['initialMPN'] = this.setCustomName(data, 'Part_Number'); this.trackingStates['initialMFR'] = this.setCustomName( data, 'Manufacturer' ); this.trackingStates['initialQTY'] = this.setCustomName(data, 'Quantity'); this.trackingStates['initialDesc'] = this.setCustomName( data, 'Description' ); } /** * Sets the final state of the mapped headers. * @param data Mapped header data. */ setFinalState(data: Array) { this.trackingStates['MPN'] = this.setCustomName(data, 'Part_Number'); this.trackingStates['MFR'] = this.setCustomName(data, 'Manufacturer'); this.trackingStates['QTY'] = this.setCustomName(data, 'Quantity'); this.trackingStates['Desc'] = this.setCustomName(data, 'Description'); } /** * Trys to match data to given tracking name * @param data Mapped header data. * @param name Tracking name. * @returns custom name for matched data or empty string. */ setCustomName(data: Array, name: string): string { const match = data.find(item => item.type === name); return match ? match.custom : ''; } /** * Mapped captured mapped headers states. * @param bomId BOM id of newly created BOM. * @returns the mapped header object ready to be sent to the tracking service. */ getMappedData(bomId: string): any { this.trackingStates['bomId'] = bomId; return this.trackingStates; } }