From 73a2ac80c74cb66cb8367ed0b5adfbe5c151b54a Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Thu, 13 Jul 2023 09:14:02 -0700 Subject: [PATCH 1/6] Fix date format in csv files Signed-off-by: Kavitha Conjeevaram Mohan --- server/routes/utils/dataReportHelpers.ts | 31 +++++++++++++++--------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index a7bee2b9..2af990bf 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -50,7 +50,11 @@ export const getSelectedFields = async (columns) => { // Build the OpenSearch query from the meta data // is_count is set to 1 if we building the count query but 0 if we building the fetch data query -export const buildRequestBody = (report: any, allowLeadingWildcards: boolean, is_count: number) => { +export const buildRequestBody = ( + report: any, + allowLeadingWildcards: boolean, + is_count: number +) => { let esbBoolQuery = esb.boolQuery(); const searchSourceJSON = report._source.searchSourceJSON; const savedObjectQuery: Query = JSON.parse(searchSourceJSON).query; @@ -59,12 +63,12 @@ export const buildRequestBody = (report: any, allowLeadingWildcards: boolean, is allowLeadingWildcards: allowLeadingWildcards, queryStringOptions: {}, ignoreFilterIfFieldNotInIndex: false, - } + }; const QueryFromSavedObject = buildOpenSearchQuery( undefined, savedObjectQuery, savedObjectFilter, - savedObjectConfig, + savedObjectConfig ); // Add time range if (report._source.timeFieldName && report._source.timeFieldName.length > 0) { @@ -125,19 +129,24 @@ export const getOpenSearchData = ( const fields = data.fields; // get all the fields of type date and format them to excel format for (let dateField of report._source.dateFields) { - const dateValue = data._source[dateField]; - if (dateValue && dateValue.length !== 0) { - if (dateValue instanceof Array) { + let keys; + keys = dateField.split('.'); + if (keys && keys.length !== 0) { + if (keys instanceof Array && keys.length > 1) { // loop through array - dateValue.forEach((element, index) => { - data._source[dateField][index] = moment( - fields[dateField][index] - ).format(dateFormat); + const firstElement = keys[0]; + keys.forEach((element, index) => { + if (index !== 0) { + // Skip the first element + data._source[firstElement][element] = moment( + fields[dateField] + ).format(dateFormat); + } }); } else { // The fields response always returns an array of values for each field // https://www.elastic.co/guide/en/elasticsearch/reference/master/search-fields.html#search-fields-response - data._source[dateField] = moment(fields[dateField][0]).format( + data._source[keys[0]] = moment(fields[dateField][0]).format( dateFormat ); } From 89e0a078f3da988a49baf58e18b0dd05430fa9b1 Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Wed, 20 Sep 2023 10:21:53 -0700 Subject: [PATCH 2/6] covered all test cases Signed-off-by: Kavitha Conjeevaram Mohan --- server/routes/utils/dataReportHelpers.ts | 44 +++++++++++++++--------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index 2af990bf..d1aa803d 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -128,27 +128,25 @@ export const getOpenSearchData = ( for (let data of valueRes.hits) { const fields = data.fields; // get all the fields of type date and format them to excel format + let tempKeyElement: string[] = []; for (let dateField of report._source.dateFields) { let keys; keys = dateField.split('.'); - if (keys && keys.length !== 0) { - if (keys instanceof Array && keys.length > 1) { - // loop through array - const firstElement = keys[0]; - keys.forEach((element, index) => { - if (index !== 0) { - // Skip the first element - data._source[firstElement][element] = moment( - fields[dateField] - ).format(dateFormat); - } - }); + if (keys.length === 1) { + data._source[keys] = moment(fields[dateField]).format(dateFormat); + } else { + let keyElement = keys.shift(); + keys.push(moment(fields[dateField]).format(dateFormat)); + const nestedJSON = arrayToNestedJSON(keys); + let keyLength = Object.keys(data._source); + if (tempKeyElement.includes(keyElement) || keyLength.length > 1) { + data._source[keyElement] = { + ...data._source[keyElement], + ...nestedJSON, + }; } else { - // The fields response always returns an array of values for each field - // https://www.elastic.co/guide/en/elasticsearch/reference/master/search-fields.html#search-fields-response - data._source[keys[0]] = moment(fields[dateField][0]).format( - dateFormat - ); + data._source[keyElement] = nestedJSON; + tempKeyElement.push(keyElement); } } } @@ -235,6 +233,18 @@ function sanitize(doc: any) { return doc; } +function arrayToNestedJSON(arr: string[]) { + if (arr.length === 0) { + return null; + } else if (arr.length === 1) { + return arr[0]; + } else { + const key = arr[0]; + const rest = arr.slice(1); + return { [key]: arrayToNestedJSON(rest) }; + } +} + const addDocValueFields = (report: any, requestBody: any) => { const docValues = []; for (const dateType of report._source.dateFields) { From e7d5290d8f4cf12d5c67817a3270929ee4cbd0ec Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Wed, 20 Sep 2023 11:28:34 -0700 Subject: [PATCH 3/6] add index Signed-off-by: Kavitha Conjeevaram Mohan --- server/routes/utils/dataReportHelpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index d1aa803d..6d54964d 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -133,10 +133,10 @@ export const getOpenSearchData = ( let keys; keys = dateField.split('.'); if (keys.length === 1) { - data._source[keys] = moment(fields[dateField]).format(dateFormat); + data._source[keys] = moment(fields[dateField][0]).format(dateFormat); } else { let keyElement = keys.shift(); - keys.push(moment(fields[dateField]).format(dateFormat)); + keys.push(moment(fields[dateField][0]).format(dateFormat)); const nestedJSON = arrayToNestedJSON(keys); let keyLength = Object.keys(data._source); if (tempKeyElement.includes(keyElement) || keyLength.length > 1) { From cf67f4a7fc0167517200271ce93c852f1f2b91df Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Mon, 2 Oct 2023 03:12:11 -0700 Subject: [PATCH 4/6] fixed jest tests Signed-off-by: Kavitha Conjeevaram Mohan --- .../__tests__/savedSearchReportHelper.test.ts | 996 ++++++++++++++++-- server/routes/utils/dataReportHelpers.ts | 60 +- 2 files changed, 974 insertions(+), 82 deletions(-) diff --git a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts index ef0c812f..4094f1cb 100644 --- a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts +++ b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts @@ -113,11 +113,76 @@ describe('test create saved search report', () => { test('create report for small data set by single search', async () => { const hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -142,17 +207,160 @@ describe('test create saved search report', () => { test('create report for large data set by scroll', async () => { const hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), - hit({ category: 'c6', customer_gender: 'Female' }), - hit({ category: 'c7', customer_gender: 'Female' }), - hit({ category: 'c8', customer_gender: 'Female' }), - hit({ category: 'c9', customer_gender: 'Female' }), - hit({ category: 'c10', customer_gender: 'Female' }), - hit({ category: 'c11', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c6', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c7', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c8', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c9', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c10', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c11', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -186,11 +394,76 @@ describe('test create saved search report', () => { input.report_definition.report_params.core_params.limit = 1; const hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -211,16 +484,146 @@ describe('test create saved search report', () => { input.report_definition.report_params.core_params.limit = 6; const hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), - hit({ category: 'c6', customer_gender: 'Female' }), - hit({ category: 'c7', customer_gender: 'Female' }), - hit({ category: 'c8', customer_gender: 'Female' }), - hit({ category: 'c9', customer_gender: 'Female' }), - hit({ category: 'c10', customer_gender: 'Female' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c6', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c7', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c8', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c9', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c10', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -249,12 +652,90 @@ describe('test create saved search report', () => { input.report_definition.report_params.core_params.limit = 10; const hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), - hit({ category: 'c6', customer_gender: 'Female' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c6', + customer_gender: 'Female', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -280,9 +761,48 @@ describe('test create saved search report', () => { test('create report for data set with comma', async () => { const hits = [ - hit({ category: ',c1', customer_gender: 'Ma,le' }), - hit({ category: 'c2,', customer_gender: 'M,ale' }), - hit({ category: ',,c3', customer_gender: 'Male,,,' }), + hit( + { + category: ',c1', + customer_gender: 'Ma,le', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2,', + customer_gender: 'M,ale', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',,c3', + customer_gender: 'Male,,,', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -305,9 +825,48 @@ describe('test create saved search report', () => { test('create report for data set with comma and custom separator', async () => { const hits = [ - hit({ category: ',c1', customer_gender: 'Ma,le' }), - hit({ category: 'c2,', customer_gender: 'M,ale' }), - hit({ category: ',,c3', customer_gender: 'Male,,,' }), + hit( + { + category: ',c1', + customer_gender: 'Ma,le', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2,', + customer_gender: 'M,ale', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',,c3', + customer_gender: 'Male,,,', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -330,15 +889,37 @@ describe('test create saved search report', () => { test('create report for data set with nested fields', async () => { const hits = [ - hit({ - 'geoip.country_iso_code': 'GB', - 'geoip.location': { lon: -0.1, lat: 51.5 }, - }), - hit({ - 'geoip.country_iso_code': 'US', - 'geoip.city_name': 'New York', - 'geoip.location': { lon: -74, lat: 40.8 }, - }), + hit( + { + 'geoip.country_iso_code': 'GB', + 'geoip.location': { lon: -0.1, lat: 51.5 }, + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + // }), + hit( + { + 'geoip.country_iso_code': 'US', + 'geoip.city_name': 'New York', + 'geoip.location': { lon: -74, lat: 40.8 }, + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + // }), ]; const client = mockOpenSearchClient( hits, @@ -363,11 +944,76 @@ describe('test create saved search report', () => { test('create report by sanitizing data set for Excel', async () => { const hits = [ - hit({ category: 'c1', customer_gender: '=Male' }), - hit({ category: 'c2', customer_gender: 'Male=' }), - hit({ category: 'c3', customer_gender: '+Ma,le' }), - hit({ category: ',-c4', customer_gender: 'Male' }), - hit({ category: ',,,@c5', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: '=Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male=', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: '+Ma,le', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',-c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',,,@c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -395,11 +1041,76 @@ describe('test create saved search report', () => { input.report_definition.report_params.core_params.excel = false; const hits = [ - hit({ category: 'c1', customer_gender: '=Male' }), - hit({ category: 'c2', customer_gender: 'Male=' }), - hit({ category: 'c3', customer_gender: '+Ma,le' }), - hit({ category: ',-c4', customer_gender: 'Male' }), - hit({ category: ',,,@c5', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: '=Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male=', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: '+Ma,le', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',-c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: ',,,@c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -425,9 +1136,48 @@ describe('test create saved search report', () => { test('create report for data set contains null field value', async () => { const hits = [ - hit({ category: 'c1', customer_gender: 'Ma' }), - hit({ category: 'c2', customer_gender: 'le' }), - hit({ category: 'c3', customer_gender: null }), + hit( + { + category: 'c1', + customer_gender: 'Ma', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'le', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: null, + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; const client = mockOpenSearchClient(hits); const { dataUrl } = await createSavedSearchReport( @@ -448,11 +1198,76 @@ test('create report for data set contains null field value', async () => { test('create report for data set with metadata fields', async () => { const metadataFields = { _index: 'nameofindex', _id: 'someid' }; let hits = [ - hit({ category: 'c1', customer_gender: 'Male' }), - hit({ category: 'c2', customer_gender: 'Male' }), - hit({ category: 'c3', customer_gender: 'Male' }), - hit({ category: 'c4', customer_gender: 'Male' }), - hit({ category: 'c5', customer_gender: 'Male' }), + hit( + { + category: 'c1', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c2', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c3', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c4', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), + hit( + { + category: 'c5', + customer_gender: 'Male', + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + customer_birth_date: '2023-04-26T04:34:32Z', + order_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } + ), ]; hits.forEach((i) => { _.merge(i, metadataFields); @@ -485,32 +1300,60 @@ test('create report for data set with metadata fields', async () => { test('create report with empty/one/multiple(list) date values', async () => { const hits = [ hit( - { category: 'c1', customer_gender: 'Ma', order_date: [] }, - { order_date: [] } + { + category: 'c1', + customer_gender: 'Ma', + order_date: [], + customer_birth_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, + }, + { + order_date: [], + customer_birth_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } ), hit( { category: 'c2', customer_gender: 'le', order_date: ['2021-12-16T14:04:55'], + customer_birth_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, }, - { order_date: ['2021-12-16T14:04:55'] } + { + order_date: ['2021-12-16T14:04:55'], + customer_birth_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } ), hit( { category: 'c3', customer_gender: 'he', order_date: ['2021-12-17T14:04:55', '2021-12-18T14:04:55'], + customer_birth_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, }, - { order_date: ['2021-12-17T14:04:55', '2021-12-18T14:04:55'] } + { + order_date: ['2021-12-17T14:04:55', '2021-12-18T14:04:55'], + customer_birth_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } ), hit( { category: 'c4', customer_gender: 'te', order_date: '2021-12-19T14:04:55', + customer_birth_date: '2023-04-26T04:34:32Z', + products: { created_on: '2023-04-26T04:34:32Z' }, }, - { order_date: ['2021-12-19T14:04:55'] } + { + order_date: ['2021-12-19T14:04:55'], + customer_birth_date: '2023-04-26T04:34:32Z', + 'products.created_on': '2023-04-26T04:34:32Z', + } ), ]; const client = mockOpenSearchClient( @@ -526,7 +1369,6 @@ test('create report with empty/one/multiple(list) date values', async () => { undefined, mockLogger ); - expect(dataUrl).toEqual( 'category,customer_gender,order_date\n' + 'c1,Ma,[]\n' + @@ -540,7 +1382,7 @@ test('create report with empty/one/multiple(list) date values', async () => { * Mock Elasticsearch client and return different mock objects based on endpoint and parameters. */ function mockOpenSearchClient( - mockHits: Array<{ _source: any }>, + mockHits: Array<{ _source: any; fields: any }>, columns = '"category", "customer_gender"' ) { let call = 0; diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index 6d54964d..8e45aa94 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -14,6 +14,7 @@ import { Query, OpenSearchQueryConfig, } from '../../../../../src/plugins/data/common'; +import { string } from 'joi'; export var metaData = { saved_search_id: null, @@ -118,9 +119,9 @@ export const buildRequestBody = ( // Fetch the data from OpenSearch export const getOpenSearchData = ( - arrayHits, - report, - params, + arrayHits: any, + report: { _source: any }, + params: { excel: any; limit: number }, dateFormat: string ) => { let hits: any = []; @@ -132,13 +133,45 @@ export const getOpenSearchData = ( for (let dateField of report._source.dateFields) { let keys; keys = dateField.split('.'); + const dateValue = data._source[dateField]; + const fieldDateValue = fields[dateField]; + // if its not a nested date field if (keys.length === 1) { - data._source[keys] = moment(fields[dateField][0]).format(dateFormat); + // if conditions to determine if the date field's value is an array or a string + if (typeof dateValue === 'string') { + data._source[keys] = moment(dateValue).format(dateFormat); + } else if ( + fieldDateValue.length !== 0 && + fieldDateValue instanceof Array + ) { + console.log('entered'); + fieldDateValue.forEach((element, index) => { + data._source[keys][index] = moment(element).format(dateFormat); + }); + } else { + data._source[keys] = []; + } + // else to cover cases with nested date fields } else { let keyElement = keys.shift(); - keys.push(moment(fields[dateField][0]).format(dateFormat)); + // if conditions to determine if the date field's value is an array or a string + if (typeof fieldDateValue === 'string') { + keys.push(moment(fieldDateValue).format(dateFormat)); + } else if ( + fieldDateValue.length !== 0 && + fieldDateValue instanceof Array + ) { + let tempArray: string[] = []; + fieldDateValue.forEach((index) => { + tempArray.push(moment(index).format(dateFormat)); + }); + keys.push(tempArray); + } else { + keys.push([]); + } const nestedJSON = arrayToNestedJSON(keys); let keyLength = Object.keys(data._source); + // to check if the nested field have anyother keys apart from date field if (tempKeyElement.includes(keyElement) || keyLength.length > 1) { data._source[keyElement] = { ...data._source[keyElement], @@ -166,6 +199,23 @@ export const getOpenSearchData = ( return hits; }; +// function getDataFieldValues (fields, dateField: string, dateFormat: string, data: any, key: string) { +// if (typeof fields[dateField] === 'string') { +// console.log('does it event enter here?'); +// data._source[key] = moment(fields[dateField]).format(dateFormat); +// } else if (fields[dateField][0] !== undefined) { +// console.log('entered'); +// data._source[key] = moment(fields[dateField][0]).format( +// dateFormat +// ); +// } else { +// console.log('else is chosen!'); +// data._source[key] = []; +// console.log('data._source inside else: ', data._source); +// } +// return data._source; +// } + //Convert the data to Csv format export const convertToCSV = async (dataset, csvSeparator) => { let convertedData: any = []; From d36d8dba5b4663979d5698497e9a6841e73f9af9 Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Mon, 2 Oct 2023 03:14:09 -0700 Subject: [PATCH 5/6] remove commented code Signed-off-by: Kavitha Conjeevaram Mohan --- server/routes/utils/dataReportHelpers.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index 8e45aa94..db15de0f 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -199,23 +199,6 @@ export const getOpenSearchData = ( return hits; }; -// function getDataFieldValues (fields, dateField: string, dateFormat: string, data: any, key: string) { -// if (typeof fields[dateField] === 'string') { -// console.log('does it event enter here?'); -// data._source[key] = moment(fields[dateField]).format(dateFormat); -// } else if (fields[dateField][0] !== undefined) { -// console.log('entered'); -// data._source[key] = moment(fields[dateField][0]).format( -// dateFormat -// ); -// } else { -// console.log('else is chosen!'); -// data._source[key] = []; -// console.log('data._source inside else: ', data._source); -// } -// return data._source; -// } - //Convert the data to Csv format export const convertToCSV = async (dataset, csvSeparator) => { let convertedData: any = []; From 91c95979f2d1858469b08250055ae71661fd0ef8 Mon Sep 17 00:00:00 2001 From: Kavitha Conjeevaram Mohan Date: Mon, 2 Oct 2023 10:32:29 -0700 Subject: [PATCH 6/6] remove commented line and console log Signed-off-by: Kavitha Conjeevaram Mohan --- server/routes/utils/__tests__/savedSearchReportHelper.test.ts | 2 -- server/routes/utils/dataReportHelpers.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts index 4094f1cb..f90c2a9e 100644 --- a/server/routes/utils/__tests__/savedSearchReportHelper.test.ts +++ b/server/routes/utils/__tests__/savedSearchReportHelper.test.ts @@ -903,7 +903,6 @@ describe('test create saved search report', () => { 'products.created_on': '2023-04-26T04:34:32Z', } ), - // }), hit( { 'geoip.country_iso_code': 'US', @@ -919,7 +918,6 @@ describe('test create saved search report', () => { 'products.created_on': '2023-04-26T04:34:32Z', } ), - // }), ]; const client = mockOpenSearchClient( hits, diff --git a/server/routes/utils/dataReportHelpers.ts b/server/routes/utils/dataReportHelpers.ts index db15de0f..718af5f3 100644 --- a/server/routes/utils/dataReportHelpers.ts +++ b/server/routes/utils/dataReportHelpers.ts @@ -144,7 +144,6 @@ export const getOpenSearchData = ( fieldDateValue.length !== 0 && fieldDateValue instanceof Array ) { - console.log('entered'); fieldDateValue.forEach((element, index) => { data._source[keys][index] = moment(element).format(dateFormat); });