Conditions | 2 |
Paths | 9 |
Total Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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'); |
||
57 | dataListLight.forEach(function (crtListParameters) { |
||
58 | // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
59 | if (myFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { |
||
60 | // records detail of current List |
||
61 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { |
||
62 | return crtListParameters[x]; |
||
63 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
64 | // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
65 | request.get(myFunctions.buildRequestQuery(targetSharePoint.URL, crtListParameters.Title, 'Fields', headerOptions)).then(function (response) { |
||
66 | var dataObject = response.d.results; |
||
67 | if (Object.keys(dataObject).length > 0) { |
||
68 | var fieldAttributes = []; |
||
69 | var counter = 0; |
||
70 | dataObject.forEach(function (item) { |
||
71 | var crtRecordFieldWillBeExtracted = myFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); |
||
72 | // for certain Lists all existing fields should be retrieved |
||
73 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { |
||
74 | crtRecordFieldWillBeExtracted = true; |
||
75 | } |
||
76 | if (crtRecordFieldWillBeExtracted) { |
||
77 | fieldAttributes[item.Title] = { |
||
78 | 'Technical Name': item.StaticName, |
||
79 | 'Type': item.TypeAsString |
||
80 | }; |
||
81 | counter++; |
||
82 | var crtListField = []; |
||
83 | var counterF = 0 |
||
84 | Object.keys(config.SharePoint.MetaDataOutput.Fields).forEach(function (itemF) { |
||
85 | crtListField[counterF] = item[config.SharePoint.MetaDataOutput.Fields[itemF]]; |
||
86 | counterF++; |
||
87 | }); |
||
88 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
89 | } |
||
90 | }); |
||
91 | // Get the actual values from current list |
||
92 | request.get(myFunctions.buildRequestQuery(targetSharePoint.URL, crtListParameters.Title, 'Items', headerOptions)).then(function (response) { |
||
93 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', fsOptions); |
||
94 | // writing headers for records within current list |
||
95 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters.EnableVersioning ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); |
||
96 | var dataObjectValues = response.d.results; |
||
97 | if (Object.keys(dataObjectValues).length > 0) { |
||
98 | dataObjectValues.forEach(function (item) { |
||
99 | var crtRecord = []; |
||
100 | var counterF = 0 |
||
101 | Object.keys(fieldAttributes).map(function (itemF) { |
||
102 | switch (fieldAttributes[itemF]['Type']) { |
||
103 | case 'DateTime': |
||
104 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']].replace('T', ' ').replace('Z', ''); |
||
105 | break; |
||
106 | case 'Lookup': |
||
107 | case 'User': |
||
108 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name'] + 'Id']; |
||
109 | break; |
||
110 | default: |
||
111 | crtRecord[counterF] = item[fieldAttributes[itemF]['Technical Name']]; |
||
112 | break; |
||
113 | } |
||
114 | counterF++; |
||
115 | }); |
||
116 | // writing current record values |
||
117 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters.EnableVersioning ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); |
||
118 | }); |
||
119 | } |
||
120 | wstream.end(function () { |
||
121 | if (config.General.Feedback.FileCompletion.OtherLists) { |
||
122 | console.log(crtListParameters.Title + '.csv has been completed!\n' + (config.General.Feedback.ContentAsJSON.OtherLists ? JSON.stringify(dataObjectValues) : '')); |
||
|
|||
123 | } |
||
124 | }); |
||
125 | }); |
||
126 | } |
||
127 | }); |
||
128 | } |
||
129 | }); |
||
130 | wStreamList.end(function () { |
||
138 |