Skip to content

Commit

Permalink
Fix undefined date error while generating CSV report (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#309) (opensearch-project#310)

* Fix undefined date while generating csv



* Add test



* Revert "Add test"

This reverts commit 9471f30.



---------


(cherry picked from commit 241c6f5)

Signed-off-by: Rupal Mahajan <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 128d67d commit cccd9e1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/routes/utils/dataReportHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const getOpenSearchData = (
let keys;
keys = dateField.split('.');
const dateValue = data._source[dateField];
const fieldDateValue = fields[dateField];
const fieldDateValue = fields !== undefined ? fields[dateField] : undefined;
const isDateFieldPresent = isKeyPresent(data._source, dateField);

if (isDateFieldPresent) {
Expand All @@ -146,7 +146,8 @@ export const getOpenSearchData = (
data._source[keys] = moment.utc(dateValue).tz(timezone).format(dateFormat);
} else if (
dateValue.length !== 0 &&
dateValue instanceof Array
dateValue instanceof Array &&
fieldDateValue !== undefined
) {
fieldDateValue.forEach((element, index) => {
data._source[keys][index] = moment.utc(element).tz(timezone).format(dateFormat);
Expand All @@ -158,11 +159,12 @@ export const getOpenSearchData = (
} else {
let keyElement = keys.shift();
// if conditions to determine if the date field's value is an array or a string
if (typeof fieldDateValue === 'string') {
if (fieldDateValue !== undefined && typeof fieldDateValue === 'string') {
keys.push(moment.utc(fieldDateValue).tz(timezone).format(dateFormat));
} else if (
dateValue.length !== 0 &&
dateValue instanceof Array
dateValue instanceof Array &&
fieldDateValue !== undefined
) {
let tempArray: string[] = [];
fieldDateValue.forEach((index) => {
Expand Down

0 comments on commit cccd9e1

Please sign in to comment.