From 9f6bbcf47b62e8588efba49139bcfce173d8158d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 21 Feb 2024 16:32:04 +0000 Subject: [PATCH] Fix undefined date error while generating CSV report (#309) * Fix undefined date while generating csv Signed-off-by: Rupal Mahajan * Add test Signed-off-by: Rupal Mahajan * Revert "Add test" This reverts commit 9471f309d12f470bd292d273537faae0256780f8. Signed-off-by: Rupal Mahajan --------- Signed-off-by: Rupal Mahajan (cherry picked from commit 241c6f5ab458ac15feba69444d4fc5249957874b) Signed-off-by: github-actions[bot] --- server/routes/utils/dataReportHelpers.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index 27349f2d..2a925d94 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -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) { @@ -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); @@ -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) => {