diff --git a/src/actions/format_processed_analytics_data.js b/src/actions/format_processed_analytics_data.js index 1d9ce714..8df8f38a 100644 --- a/src/actions/format_processed_analytics_data.js +++ b/src/actions/format_processed_analytics_data.js @@ -17,7 +17,7 @@ class FormatProcessedAnalyticsData extends Action { */ async executeStrategy(context) { context.logger.debug("Formatting analytics data"); - const formattedAnalyticsData = {}; + let formattedAnalyticsData = {}; for (const format of context.appConfig.formats) { formattedAnalyticsData[format] = await ResultFormatter.formatResult( context.processedAnalyticsData, @@ -29,6 +29,7 @@ class FormatProcessedAnalyticsData extends Action { } context.processedAnalyticsData = undefined; context.formattedAnalyticsData = formattedAnalyticsData; + formattedAnalyticsData = undefined; } } diff --git a/src/process_results/result_formatter.js b/src/process_results/result_formatter.js index 2d57de72..142cd93a 100644 --- a/src/process_results/result_formatter.js +++ b/src/process_results/result_formatter.js @@ -33,12 +33,11 @@ const _formatJSON = (result, { slim }) => { }; const _formatCSV = (result) => { - const mappedData = _mapCSVHeaders(result.data); - return csv.writeToString(mappedData, { headers: true }); + return csv.writeToString(_mapCSVHeaders(result.data), { headers: true }); }; function _mapCSVHeaders(dataArray) { - return dataArray.map((dataItem) => { + return dataArray.forEach((dataItem, index) => { const newDataItem = {}; Object.keys(dataItem).forEach((key) => { if (_keyMappings[key]) { @@ -48,7 +47,7 @@ function _mapCSVHeaders(dataArray) { } }); - return newDataItem; + dataArray[index] = newDataItem; }); }