Conditions | 2 |
Paths | 5 |
Total Lines | 87 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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'); |
||
33 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
34 | // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
35 | if (MyCustomFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { |
||
36 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
37 | return crtListParameters[x]; |
||
38 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
39 | // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
40 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, crtListParameters.Title, 'Fields', headerOptions)).then(function (response) { |
||
41 | var dataObject = response.d.results; |
||
42 | if (Object.keys(dataObject).length > 0) { |
||
43 | var fieldAttributes = []; |
||
44 | var counter = 0; |
||
45 | dataObject.forEach(function (item) { |
||
46 | 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 |
||
47 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
48 | crtRecordFieldWillBeExtracted = true; |
||
49 | } |
||
50 | if (crtRecordFieldWillBeExtracted) { |
||
51 | fieldAttributes[item.Title] = { |
||
52 | 'Technical Name': item.StaticName, |
||
53 | 'Type': item.TypeAsString |
||
54 | }; |
||
55 | counter++; |
||
56 | var crtListField = []; |
||
57 | var counterF = 0; |
||
58 | Object.keys(config.SharePoint.MetaDataOutput.Fields).forEach(function (itemF) { |
||
59 | crtListField[counterF] = item[config.SharePoint.MetaDataOutput.Fields[itemF]]; |
||
60 | counterF++; |
||
61 | }); |
||
62 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
63 | } |
||
64 | }); |
||
65 | // Get the actual values from current list |
||
66 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, crtListParameters.Title, 'Items', headerOptions, crtListParameters.Records)).then(function (response) { |
||
67 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', fsOptions); |
||
68 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); // writing headers for records within current list |
||
69 | var dataObjectValues = response.d.results; |
||
70 | if (Object.keys(dataObjectValues).length > 0) { |
||
71 | dataObjectValues.forEach(function (item) { |
||
72 | var crtRecord = []; |
||
73 | var counterF = 0; |
||
74 | Object.keys(fieldAttributes).map(function (itemF) { |
||
75 | switch (fieldAttributes[itemF]['Type']) { |
||
76 | case 'DateTime': |
||
77 | if (item[fieldAttributes[itemF]['Technical Name']] === null) { |
||
78 | crtRecord[counterF] = ''; |
||
79 | } else { |
||
80 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']].replace('T', ' ').replace('Z', ''); |
||
81 | } |
||
82 | break; |
||
83 | case 'Lookup': |
||
84 | case 'User': |
||
85 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name'] + 'Id']; |
||
86 | break; |
||
87 | default: |
||
88 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']]; |
||
89 | break; |
||
90 | } |
||
91 | counterF++; |
||
92 | }); |
||
93 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); // writing current record values |
||
94 | }); |
||
95 | } |
||
96 | wstream.end(); |
||
97 | }); |
||
98 | } |
||
99 | }); |
||
100 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, crtListParameters.Title, 'Views', headerOptions)).then(function (responseViews) { |
||
101 | var dataViewObject = responseViews.d.results; |
||
102 | if (Object.keys(dataViewObject).length > 0) { |
||
103 | dataViewObject.forEach(function (crtView) { |
||
104 | var crtRecordView = []; |
||
105 | var counterV = 0; |
||
106 | Object.keys(config.SharePoint.MetaDataOutput.Views).map(function (itemV) { |
||
107 | if (config.SharePoint.MetaDataOutput.Views[itemV] === 'HtmlSchemaXml') { |
||
108 | crtRecordView[counterV] = JSON.stringify(crtView[config.SharePoint.MetaDataOutput.Views[itemV]]); |
||
109 | } else { |
||
110 | crtRecordView[counterV] = crtView[config.SharePoint.MetaDataOutput.Views[itemV]]; |
||
111 | } |
||
112 | counterV++; |
||
113 | }); |
||
114 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtRecordView.join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
115 | }); |
||
116 | } |
||
117 | }); |
||
118 | } |
||
119 | }); |
||
120 | wStreamList.end(); |
||
157 |