| Conditions | 2 |
| Paths | 5 |
| Total Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var spauth = require('node-sp-auth'); |
||
| 29 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
| 30 | if (MyCustomFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
| 31 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
| 32 | return crtListParameters[x]; |
||
| 33 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
| 34 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (response) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
| 35 | var dataObject = response.d.results; |
||
| 36 | if (Object.keys(dataObject).length > 0) { |
||
| 37 | var fieldAttributes = []; |
||
| 38 | var counter = 0; |
||
| 39 | dataObject.forEach(function (item) { |
||
| 40 | var crtRecordFieldWillBeExtracted = MyCustomFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); // check current Field against configured BlackList and WhiteList besides considering user defined Fields |
||
| 41 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
| 42 | crtRecordFieldWillBeExtracted = true; |
||
| 43 | } |
||
| 44 | if (crtRecordFieldWillBeExtracted) { |
||
| 45 | fieldAttributes[item.Title] = { |
||
| 46 | 'Technical Name': item.StaticName, |
||
| 47 | 'Type': item.TypeAsString |
||
| 48 | }; |
||
| 49 | counter++; |
||
| 50 | var crtListField = []; |
||
| 51 | var counterF = 0; |
||
| 52 | Object.keys(config.SharePoint.MetaDataOutput.Fields).forEach(function (itemF) { |
||
| 53 | crtListField[counterF] = item[config.SharePoint.MetaDataOutput.Fields[itemF]]; |
||
| 54 | counterF++; |
||
| 55 | }); |
||
| 56 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
| 57 | } |
||
| 58 | }); |
||
| 59 | var internalQueryStructureItem = MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records); |
||
| 60 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureItem, crtListParameters.Title, 'Items', data)).then(function (response) { // Get the actual values from current list |
||
| 61 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', {encoding: 'utf8'}); |
||
| 62 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); // writing headers for records within current list |
||
| 63 | var dataObjectValues = response.d.results; |
||
| 64 | if (Object.keys(dataObjectValues).length > 0) { |
||
| 65 | dataObjectValues.forEach(function (item) { |
||
| 66 | var crtRecord = MyCustomFunctions.buildCurrentItemValues(fieldAttributes, item); |
||
| 67 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); // writing current record values |
||
| 68 | }); |
||
| 69 | } |
||
| 70 | wstream.end(); |
||
| 71 | }); |
||
| 72 | } |
||
| 73 | }); |
||
| 74 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
| 75 | var dataViewObject = responseViews.d.results; |
||
| 76 | if (Object.keys(dataViewObject).length > 0) { |
||
| 77 | dataViewObject.forEach(function (crtView) { |
||
| 78 | var crtRecordView = []; |
||
| 79 | var counterV = 0; |
||
| 80 | Object.keys(config.SharePoint.MetaDataOutput.Views).map(function (itemV) { |
||
| 81 | if (config.SharePoint.MetaDataOutput.Views[itemV] === 'HtmlSchemaXml') { |
||
| 82 | crtRecordView[counterV] = JSON.stringify(crtView[config.SharePoint.MetaDataOutput.Views[itemV]]); |
||
| 83 | } else { |
||
| 84 | crtRecordView[counterV] = crtView[config.SharePoint.MetaDataOutput.Views[itemV]]; |
||
| 85 | } |
||
| 86 | counterV++; |
||
| 87 | }); |
||
| 88 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtRecordView.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 89 | }); |
||
| 90 | } |
||
| 91 | }); |
||
| 92 | } |
||
| 93 | }); |
||
| 94 | wStreamList.end(); |
||
| 131 |