-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feat : added target sum mapping #825
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ import config from "../config/index"; | |||||||||||||||
import { v4 as uuidv4 } from 'uuid'; | ||||||||||||||||
import { produceModifiedMessages } from '../kafka/Listener' | ||||||||||||||||
import { confirmProjectParentCreation, createProjectCampaignResourcData, getCampaignSearchResponse, getHierarchy, handleResouceDetailsError, projectCreate } from "../api/campaignApis"; | ||||||||||||||||
import { getCampaignNumber, createAndUploadFile, getSheetData, createExcelSheet, getAutoGeneratedBoundaryCodesHandler, getTargetSheetData, createBoundaryEntities, createBoundaryRelationship, getMDMSV1Data, callMdmsV2Data } from "../api/genericApis"; | ||||||||||||||||
import { getCampaignNumber, createAndUploadFile, getSheetData, createExcelSheet, getAutoGeneratedBoundaryCodesHandler, createBoundaryEntities, createBoundaryRelationship, getMDMSV1Data, callMdmsV2Data, getTargetSheetDataAfterCode } from "../api/genericApis"; | ||||||||||||||||
import { getFormattedStringForDebug, logger } from "./logger"; | ||||||||||||||||
import createAndSearch from "../config/createAndSearch"; | ||||||||||||||||
import { addDataToSheet, changeFirstRowColumnColour, createBoundaryDataMainSheet, createReadMeSheet, findMapValue, getBoundaryRelationshipData, getConfigurableColumnHeadersFromSchemaForTargetSheet, getLocalizedHeaders, getLocalizedMessagesHandler, modifyBoundaryData, replicateRequest, throwError } from "./genericUtils"; | ||||||||||||||||
|
@@ -1231,9 +1231,9 @@ async function getCodesTarget(request: any, localizationMap?: any) { | |||||||||||||||
if (!fileResponse?.fileStoreIds?.[0]?.url) { | ||||||||||||||||
throwError("FILE", 500, "DOWNLOAD_URL_NOT_FOUND"); | ||||||||||||||||
} | ||||||||||||||||
const targetData = await getTargetSheetData(fileResponse?.fileStoreIds?.[0]?.url, true, true); | ||||||||||||||||
const boundaryTargetMapping: any = {}; | ||||||||||||||||
const codeColumnName = getLocalizedName(createAndSearch?.boundaryWithTarget?.boundaryValidation?.column, localizationMap) | ||||||||||||||||
const targetData = await getTargetSheetDataAfterCode(fileResponse?.fileStoreIds?.[0]?.url, true, true, codeColumnName); | ||||||||||||||||
const boundaryTargetMapping: any = {}; | ||||||||||||||||
Comment on lines
+1235
to
+1236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using the delete operator for performance reasons. Consider setting the property to undefined instead. - delete request.body.ExistingCampaignDetails;
+ request.body.ExistingCampaignDetails = undefined;
Ensure proper error handling for potential undefined values when using optional chaining. - const targetData = await getTargetSheetDataAfterCode(fileResponse?.fileStoreIds?.[0]?.url, true, true, codeColumnName);
+ if (!fileResponse?.fileStoreIds?.[0]?.url) {
+ throw new Error("URL is undefined");
+ }
+ const targetData = await getTargetSheetDataAfterCode(fileResponse.fileStoreIds[0].url, true, true, codeColumnName); Committable suggestion
Suggested change
|
||||||||||||||||
// Iterate through each key in targetData | ||||||||||||||||
for (const key in targetData) { | ||||||||||||||||
// Iterate through each entry in the array under the current key | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,7 @@ import { getLocaleFromRequest, getLocalisationModuleName } from "./localisationU | |||||||||||||||||||||
import { getBoundaryColumnName, getBoundaryTabName } from "./boundaryUtils"; | ||||||||||||||||||||||
import { getBoundaryDataService } from "../service/dataManageService"; | ||||||||||||||||||||||
import { addDataToSheet, formatWorksheet, getNewExcelWorkbook } from "./excelUtils"; | ||||||||||||||||||||||
import createAndSearch from "../config/createAndSearch"; | ||||||||||||||||||||||
const NodeCache = require("node-cache"); | ||||||||||||||||||||||
|
||||||||||||||||||||||
const updateGeneratedResourceTopic = config?.kafka?.KAFKA_UPDATE_GENERATED_RESOURCE_DETAILS_TOPIC; | ||||||||||||||||||||||
|
@@ -562,10 +563,16 @@ function changeFirstRowColumnColour(facilitySheet: any, color: any, columnNumber | |||||||||||||||||||||
firstHeaderCell.fill = { | ||||||||||||||||||||||
type: 'pattern', | ||||||||||||||||||||||
pattern: 'solid', | ||||||||||||||||||||||
fgColor: { argb: color } // Orange color | ||||||||||||||||||||||
fgColor: { argb: color } | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function hideUniqueIdentifierColumn(sheet: any, column: any) { | ||||||||||||||||||||||
if (column) { | ||||||||||||||||||||||
sheet.getColumn(column).hidden = true | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+570
to
+574
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the - if (column) {
+ if (column && sheet.getColumn(column)) {
sheet.getColumn(column).hidden = true
} This change ensures that the function checks whether the column exists before attempting to hide it, preventing runtime errors if the column is not present. Committable suggestion
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
async function createFacilityAndBoundaryFile(facilitySheetData: any, boundarySheetData: any, request: any, localizationMap?: any) { | ||||||||||||||||||||||
const workbook = getNewExcelWorkbook(); | ||||||||||||||||||||||
|
@@ -582,6 +589,7 @@ async function createFacilityAndBoundaryFile(facilitySheetData: any, boundaryShe | |||||||||||||||||||||
// Add facility sheet data | ||||||||||||||||||||||
const facilitySheet = workbook.addWorksheet(localizedFacilityTab); | ||||||||||||||||||||||
addDataToSheet(facilitySheet, facilitySheetData, undefined, undefined, true); | ||||||||||||||||||||||
hideUniqueIdentifierColumn(facilitySheet, createAndSearch?.["facility"]?.uniqueIdentifierColumn); | ||||||||||||||||||||||
changeFirstRowColumnColour(facilitySheet, 'E06666'); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Add boundary sheet to the workbook | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comprehensive error handling in
getTargetSheetDataAfterCode
The function
getTargetSheetDataAfterCode
lacks comprehensive error handling. While there is a console warning when a column is not found, it would be beneficial to handle potential errors that could arise from asynchronous operations such as file reading or data processing. Consider adding try-catch blocks around these operations to ensure that any exceptions are caught and handled gracefully.