| Conditions | 1 |
| Paths | 1 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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'); |
||
| 10 | .then(function (data) { |
||
| 11 | var internalQueryStructureGeneric = MyCustomFunctions.internalQueryStructureArray(0); |
||
| 12 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'Lists', data)).then(function (responseList) { |
||
| 13 | if (Object.keys(responseList.d.results).length > 0) { |
||
| 14 | var wStreamListViews = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Views + '.csv', {encoding: 'utf8'}); // initiate MetaData for Views |
||
| 15 | wStreamListViews.write('"List Name"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Views).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Views |
||
| 16 | var dataListLight = []; |
||
| 17 | var counter = 0; |
||
| 18 | responseList.d.results.forEach(function (itemList) { |
||
| 19 | dataListLight[counter] = MyCustomFunctions.buildCurrentListAttributeValues(config.SharePoint.MetaDataOutput.Lists, itemList); |
||
| 20 | counter++; |
||
| 21 | }); |
||
| 22 | var wStreamList = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Lists + '.csv', {encoding: 'utf8'}); // initiate MetaData for Lists |
||
| 23 | wStreamList.write('"' + Object.keys(dataListLight[0]).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Lists |
||
| 24 | var wStreamListFields = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Fields + '.csv', {encoding: 'utf8'}); // initiate MetaData for Fields |
||
| 25 | wStreamListFields.write('"List"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Fields).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Fields |
||
| 26 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
| 27 | 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 |
||
| 28 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
| 29 | return crtListParameters[x]; |
||
| 30 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
| 31 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (responseField) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
| 32 | if (Object.keys(responseField.d.results).length > 0) { |
||
| 33 | var fieldAttributes = []; |
||
| 34 | var counter = 0; |
||
| 35 | responseField.d.results.forEach(function (itemField) { |
||
| 36 | var crtRecordFieldWillBeExtracted = MyCustomFunctions.decideBlackListWhiteList(itemField.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, itemField.InternalName); // check current Field against configured BlackList and WhiteList besides considering user defined Fields |
||
| 37 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
| 38 | crtRecordFieldWillBeExtracted = true; |
||
| 39 | } |
||
| 40 | if (crtRecordFieldWillBeExtracted) { |
||
| 41 | fieldAttributes[itemField.Title] = {'Technical Name': itemField.StaticName, 'Type': itemField.TypeAsString}; |
||
| 42 | counter++; |
||
| 43 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Fields, itemField).join('"' + config.General.ListSeparator + '"') + '"\n'); // fields of current List |
||
| 44 | } |
||
| 45 | }); |
||
| 46 | var internalQueryStructureItem = MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records); |
||
| 47 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureItem, crtListParameters.Title, 'Items', data)).then(function (responseListRecord) { // Get the actual values from current list |
||
| 48 | MyCustomFunctions.manageRequestIntoCSVfile({'filePath': config.General.PathForExtracts, 'fileName': crtListParameters.Title, 'ListSeparator': config.General.ListSeparator}, crtListParameters, responseListRecord, fieldAttributes, fs); |
||
| 49 | }); |
||
| 50 | } |
||
| 51 | }); |
||
| 52 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
| 53 | if (Object.keys(responseViews.d.results).length > 0) { |
||
| 54 | responseViews.d.results.forEach(function (crtView) { |
||
| 55 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Views, crtView).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current Views record values |
||
| 56 | }); |
||
| 57 | } |
||
| 58 | }); |
||
| 59 | } |
||
| 60 | }); |
||
| 61 | wStreamList.end(); |
||
| 62 | } |
||
| 63 | }); |
||
| 64 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'SiteGroups', data)).then(function (responseSiteGroups) { |
||
| 65 | if (Object.keys(responseSiteGroups.d.results).length > 0) { |
||
| 66 | var wStreamGroups = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroups + '.csv', {encoding: 'utf8'}); // initiate MetaData for Groups |
||
| 67 | wStreamGroups.write('"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroups).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Groups |
||
| 68 | var wStreamGroupMembers = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroupMembers + '.csv', {encoding: 'utf8'}); // initiate MetaData for Group Members |
||
| 69 | wStreamGroupMembers.write('"Group"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroupMembers).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Group Members |
||
| 70 | responseSiteGroups.d.results.forEach(function (crtItemGroup) { |
||
| 71 | wStreamGroups.write('"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroups, crtItemGroup).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 72 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtItemGroup.Id, 'GroupMembers', data)).then(function (responseMembers) { |
||
| 73 | if (Object.keys(responseMembers.d.results).length > 0) { |
||
| 74 | responseMembers.d.results.forEach(function (crtItemGroupMember) { |
||
| 75 | wStreamGroupMembers.write('"' + crtItemGroup.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroupMembers, crtItemGroupMember).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 76 | }); |
||
| 77 | } |
||
| 78 | }); |
||
| 79 | }); |
||
| 80 | wStreamGroups.end(); |
||
| 81 | } |
||
| 82 | }); |
||
| 83 | }); |
||
| 84 |