import { Injectable } from '@angular/core'; import { trim } from 'lodash-es'; import { CommonUtils } from '@farris/ui-common'; @Injectable() export class LookupDefaultMapping { constructor(private utils: CommonUtils) {} lookupFieldMap = (helpData, mapFields, dataObj) => { if (mapFields) { const helpFields = Object.keys(mapFields); helpFields.forEach( (f: any) => { let val = ''; if (helpData) { if (helpData instanceof Array) { val = helpData.map( (h: any) => { return this.utils.getValue(f, h); }).join(','); } else { val = this.utils.getValue(f, helpData); } } mapFields[f].split(',').forEach( (ff: any) => { const field = trim(ff); this.utils.setValue(dataObj, field, val); }); }); } } }