Conditions | 2 |
Paths | 9 |
Total Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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'); |
||
69 | }).then(function (response) { |
||
70 | var dataObject = response.d.results; |
||
71 | if (Object.keys(dataObject).length > 0) { |
||
72 | var headersArray = []; |
||
73 | var fieldsArray = []; |
||
74 | var fieldsTypeArray = []; |
||
75 | var counter = 0; |
||
76 | dataObject.forEach(function (item) { |
||
77 | var crtRecordFieldWillBeExtracted = myFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); |
||
78 | // for certain Lists all existing fields should be retrieved |
||
79 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListName) > -1) { |
||
80 | crtRecordFieldWillBeExtracted = true; |
||
81 | } |
||
82 | if (crtRecordFieldWillBeExtracted) { |
||
83 | headersArray[counter] = item.Title; |
||
84 | fieldsArray[counter] = item.StaticName; |
||
85 | fieldsTypeArray[counter] = item.TypeAsString; |
||
86 | counter++; |
||
87 | var crtListField = []; |
||
88 | var counterF = 0 |
||
89 | Object.keys(inMetaDataFields).forEach(function (itemF) { |
||
90 | crtListField[counterF] = item[inMetaDataFields[itemF]]; |
||
91 | counterF++; |
||
92 | }); |
||
93 | wStreamListFields.write('"' + crtListName + '"' + config.General.ListSeparator + '"' + crtListField.join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
94 | } |
||
95 | }); |
||
96 | // Get the actual values from current list |
||
97 | request.get({ |
||
98 | url: targetSharePoint.URL + '_api/web/lists/GetByTitle(\'' + crtListName + '\')/Items', |
||
99 | headers: headerOptions, |
||
100 | json: true |
||
101 | }).then(function (response) { |
||
102 | var fieldsLength = fieldsArray.length; |
||
103 | // output to file only if detectable fields are in scope |
||
104 | if (fieldsLength > 0) { |
||
105 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListName + '.csv', fsOptions); |
||
106 | // writing headers for records within current list |
||
107 | wstream.write('"' + headersArray.join('"' + config.General.ListSeparator + '"') + (crtListParameters.EnableVersioning ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); |
||
108 | var dataObjectValues = response.d.results; |
||
109 | if (Object.keys(dataObjectValues).length > 0) { |
||
110 | dataObjectValues.forEach(function (item) { |
||
111 | var crtRecord = []; |
||
112 | for (var counterF = 0; counterF < fieldsLength; counterF++) { |
||
113 | switch (fieldsTypeArray[counterF]) { |
||
114 | case 'DateTime': |
||
115 | crtRecord[counterF] = item[fieldsArray[counterF]].replace('T', ' ').replace('Z', ''); |
||
116 | break; |
||
117 | case 'Lookup': |
||
118 | case 'User': |
||
119 | crtRecord[counterF] = item[fieldsArray[counterF] + 'Id']; |
||
120 | break; |
||
121 | default: |
||
122 | crtRecord[counterF] = item[fieldsArray[counterF]]; |
||
123 | break; |
||
124 | } |
||
125 | } |
||
126 | // writing current record values |
||
127 | wstream.write('"' + crtRecord.join('"' + config.General.ListSeparator + '"') + (crtListParameters.EnableVersioning ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); |
||
128 | }); |
||
129 | } |
||
130 | wstream.end(function () { |
||
131 | if (config.General.Feedback.FileCompletion.OtherLists) { |
||
132 | console.log(crtListName + '.csv has been completed!\n' + (config.General.Feedback.ContentAsJSON.OtherLists ? JSON.stringify(dataObjectValues) : '')); |
||
|
|||
133 | } |
||
134 | }); |
||
135 | } |
||
136 | }); |
||
137 | } |
||
138 | }); |
||
139 | } |
||
149 |