From e6a52b4ab97442b0e567e1781b67cadafb71225c Mon Sep 17 00:00:00 2001 From: Gauravudia Date: Tue, 13 Feb 2024 10:35:35 +0530 Subject: [PATCH] refactor: apply review suggestions --- src/v0/util/index.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/v0/util/index.js b/src/v0/util/index.js index 84c3277ad6..0cc66b2d7a 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -33,6 +33,7 @@ const { AUTH_STATUS_INACTIVE, } = require('../../adapters/networkhandler/authConstants'); const { FEATURE_FILTER_CODE, FEATURE_GZIP_SUPPORT } = require('./constant'); +const { CommonUtils } = require('../../util/common'); // ======================================================================== // INLINERS @@ -2143,17 +2144,10 @@ const parseConfigArray = (arr, key) => { * @returns */ const findExistingBatch = (batch, metadataMap) => { - let existingBatch = null; - - // eslint-disable-next-line no-restricted-syntax - for (const metadataItem of batch.metadata) { - if (metadataMap.has(metadataItem.jobId)) { - existingBatch = metadataMap.get(metadataItem.jobId); - break; - } - } - - return existingBatch; + const existingMetadataItem = batch.metadata.find((metadataItem) => + metadataMap.has(metadataItem.jobId), + ); + return existingMetadataItem ? metadataMap.get(existingMetadataItem.jobId) : null; }; /** @@ -2192,10 +2186,8 @@ const combineBatchRequestsWithSameJobIds = (inputBatches) => { if (existingBatch) { // Merge batchedRequests arrays existingBatch.batchedRequest = [ - ...(Array.isArray(existingBatch.batchedRequest) - ? existingBatch.batchedRequest - : [existingBatch.batchedRequest]), - ...(Array.isArray(batch.batchedRequest) ? batch.batchedRequest : [batch.batchedRequest]), + ...CommonUtils.toArray(existingBatch.batchedRequest), + ...CommonUtils.toArray(batch.batchedRequest), ]; // Merge metadata