daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. return metadataResults.map(entityMetadata => overrideEntityProperties({ entityMetadata, defaultObjectsMap, lookupMetaMap }));
  2.     // metadataResults.forEach(entityMetadata => {
  3.     //   // Check if override or default value exists
  4.     //   if(METADATA_OVERRIDES[entityMetadata.name] || defaultObjectsMap[entityMetadata.name] || lookupMetaMap[entityMetadata.name]){  // Check if override entry exists in METADATA_OVERRIDES
  5.     //     entityMetadata.metadata.fields.forEach(field => {
  6.     //
  7.     //       // Adding overrides object to metadata
  8.     //       const overrides = get(METADATA_OVERRIDES, [entityMetadata.name, field.name]);
  9.     //       if(overrides !== undefined){
  10.     //         field.overrides = overrides;
  11.     //
  12.     //         // Changing isCreatable & isUpdatable for ProposedValue and NegotiatedValue field
  13.     //         if(field.name === 'ProposedValue'){
  14.     //           field.isCreatable = field.overrides.content.isCreatable || field.overrides.currencyCode.isCreatable;
  15.     //           field.isUpdatable = field.overrides.content.isUpdatable || field.overrides.currencyCode.isUpdatable;
  16.     //         } else if(field.name === 'NegotiatedValue') {
  17.     //           field.isCreatable = field.overrides.content.isCreatable || field.overrides.currencyCode.isCreatable;
  18.     //           field.isUpdatable = field.overrides.content.isUpdatable || field.overrides.currencyCode.isUpdatable;
  19.     //         }
  20.     //       }
  21.     //      
  22.     //       // Adding default object to metadata
  23.     //       if(defaultObjectsMap[entityMetadata.name]){
  24.     //         entityMetadata.metadata.hasDefaultFields = true; // Entity level property. True = entity has fields with default
  25.     //         const defaultValue = get(defaultObjectsMap, [entityMetadata.name, field.name]);
  26.     //         if(defaultValue !== undefined){
  27.     //           field.isNullable = true; // Remove required requirement from fields with default
  28.     //           field.isDefaulted = true;
  29.     //           field.defaultValue = defaultValue; // Add default value to metadata
  30.     //         }
  31.     //       }
  32.     //
  33.     //       // setting up lookup fields
  34.     //       const lookupMeta = get(lookupMetaMap, [entityMetadata.name, field.name]);
  35.     //       if (lookupMeta !== undefined){
  36.     //         field.dataType = 'reference';
  37.     //         field.label = field.label.replace('UUID', '').replace('ID', '');
  38.     //         field.referencesTo = lookupMeta.map(item => item.lookupObject);
  39.     //         field.lookupMeta = lookupMeta;
  40.     //       }
  41.     //     });
  42.     //   }
  43.     //   entityDetails.push(entityMetadata.metadata);
  44.     // });
  45.     // return entityDetails;
  46.    
  47.    
  48.    
  49.    
  50. function overrideEntityProperties({ entityMetadata, defaultObjectsMap, lookupMetaMap }) {
  51.  
  52.   if(!isApplyEntityOverrides({ entityMetadata, defaultObjectsMap, lookupMetaMap })) {
  53.     return entityMetadata.metadata;
  54.   }
  55.  
  56.   entityMetadata.metadata.fields.forEach(field => {
  57.  
  58.     // Adding overrides object to metadata
  59.     // const overrides = get(METADATA_OVERRIDES, [entityMetadata.name, field.name]);
  60.     // if(overrides !== undefined){
  61.     //   field.overrides = overrides;
  62.     //
  63.     //   // Changing isCreatable & isUpdatable for ProposedValue and NegotiatedValue field
  64.     //   if(field.name === 'ProposedValue'){
  65.     //     field.isCreatable = field.overrides.content.isCreatable || field.overrides.currencyCode.isCreatable;
  66.     //     field.isUpdatable = field.overrides.content.isUpdatable || field.overrides.currencyCode.isUpdatable;
  67.     //   } else if(field.name === 'NegotiatedValue') {
  68.     //     field.isCreatable = field.overrides.content.isCreatable || field.overrides.currencyCode.isCreatable;
  69.     //     field.isUpdatable = field.overrides.content.isUpdatable || field.overrides.currencyCode.isUpdatable;
  70.     //   }
  71.     // }
  72.  
  73.     addOverridesToMetadata({ entityMetadata, field });
  74.  
  75.     // Adding default object to metadata
  76.     if(defaultObjectsMap[entityMetadata.name]){
  77.       entityMetadata.metadata.hasDefaultFields = true; // Entity level property. True = entity has fields with default
  78.       const defaultValue = get(defaultObjectsMap, [entityMetadata.name, field.name]);
  79.       if(defaultValue !== undefined){
  80.         field.isNullable = true; // Remove required requirement from fields with default
  81.         field.isDefaulted = true;
  82.         field.defaultValue = defaultValue; // Add default value to metadata
  83.       }
  84.     }
  85.  
  86.     // setting up lookup fields
  87.     const lookupMeta = get(lookupMetaMap, [entityMetadata.name, field.name]);
  88.     if (lookupMeta !== undefined){
  89.       field.dataType = 'reference';
  90.       field.label = field.label.replace('UUID', '').replace('ID', '');
  91.       field.referencesTo = lookupMeta.map(item => item.lookupObject);
  92.       field.lookupMeta = lookupMeta;
  93.     }
  94.   });
  95.  
  96.   return entityMetadata.metadata;
  97. }
  98.  
  99. function isApplyEntityOverrides({ entityMetadata, defaultObjectsMap, lookupMetaMap }) {
  100.   return METADATA_OVERRIDES[entityMetadata.name] || defaultObjectsMap[entityMetadata.name] || lookupMetaMap[entityMetadata.name];
  101. }
  102.  
  103. function addOverridesToMetadata({ entityMetadata, field }) {
  104.   const metadataFields = METADATA_OVERRIDES[entityMetadata.name].fields;
  105.   const metadataOverrideProps = metadataFields && metadataFields[field.name];
  106.  
  107.   if(!metadataOverrideProps) {
  108.     return;
  109.   }
  110.  
  111.   Object.assign(field, metadataOverrideProps, {
  112.     overrides: metadataOverrideProps,
  113.     isDefaulted: has(metadataOverrideProps, 'defaultValue')
  114.   });
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top