Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined date error while generating CSV report #309

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading