import _ from 'lodash';


export const unexistedUID = '00000000-0000-0000-C000-000000000046';

export function initObject(classDef, attrs, id, params) {
  return new classDef({ ...attrs, ...{ id }, ...params });
}

export function prepareModelPayload(payload, namesMapping, valuesMapping) {
  return _.transform(payload, (result, val, key) => {
    let mappedVal = val;

    if (valuesMapping[key]) {
      mappedVal = valuesMapping[key](val);
    }

    const mappedKey = namesMapping[key];

    if (mappedKey) {
      result[mappedKey] = mappedVal;
    }
  });
}

@@ -184,17 +184,10 @@
 rs, 
-...%7B id %7D
+id
 , ..
@@ -283,34 +283,76 @@
 %7B%0A  
-return _.transform
+const result = %7B%7D;%0A  const keys = _.intersection(Object.keys
 (payload
 , (r
@@ -351,48 +351,84 @@
 load
+)
 , 
-(result, val,
+Object.keys(namesMapping));%0A%0A  for (const key of
  key
+s
 )
- =%3E
  %7B%0A    
-le
+cons
 t mapped
 Val 
@@ -427,32 +427,17 @@
 pped
-Val = val;%0A%0A    if (valu
+Key = nam
 esMa
@@ -446,25 +446,27 @@
 ing%5Bkey%5D
-) %7B%0A     
+;%0A    const
  mappedV
@@ -492,87 +492,60 @@
 key%5D
-(val);%0A    %7D%0A%0A    const mappedKey = namesMapping%5Bkey%5D;%0A%0A    if (mappedK
+ ? valuesMapping%5Bkey%5D(payload%5Bk
 ey
+%5D
 ) 
-%7B%0A  
+: payload%5Bkey%5D;%0A
     
@@ -581,16 +581,26 @@
 ;%0A  
-  %7D%0A  %7D)
+%7D%0A%0A  return result
 ;%0A%7D%0A

Rewrite and simplify prepareModelPayload function