Skip to content

Commit

Permalink
Update genericUtils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nitish-egov authored May 30, 2024
1 parent 395253b commit 3058897
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,19 +738,32 @@ function matchData(request: any, datas: any, searchedDatas: any, createAndSearch
request.body.sheetErrorDetails = request?.body?.sheetErrorDetails ? [...request?.body?.sheetErrorDetails, ...errors] : errors;
}

function modifyBoundaryData(boundaryData: unknown[], localizationMap?: any) {
function modifyBoundaryData(boundaryData: any[], localizationMap?: any) {
// Initialize arrays to store data
const withBoundaryCode: { key: string, value: string }[][] = [];
const withoutBoundaryCode: { key: string, value: string }[][] = [];

// Get the key for the boundary code
const boundaryCodeKey = getLocalizedName(config?.boundary?.boundaryCode, localizationMap);

// Process each object in boundaryData
boundaryData.forEach((obj: any) => {
// Convert object entries to an array of {key, value} objects
const row: any = Object.entries(obj)
.filter(([key, value]) => key !== getLocalizedName(config?.boundary?.boundaryCode,localizationMap) && value !== null && value !== undefined)
.map(([key, value]: [string, any]) => ({ key, value: value.toString().replace(/_/g, ' ').trim() }));
.filter(([key, value]: [string, any]) => value !== null && value !== undefined) // Filter out null or undefined values
.map(([key, value]: [string, any]) => {
// Check if the current key is the "Boundary Code" key
if (key === boundaryCodeKey) {
// Keep the "Boundary Code" value as is without transformation
return { key, value: value.toString() };
} else {
// Transform other values
return { key, value: value.toString().replace(/_/g, ' ').trim() };
}
});

// Determine whether the object has a boundary code property
const hasBoundaryCode = obj.hasOwnProperty(getLocalizedName(config?.boundary?.boundaryCode, localizationMap));
// Determine whether the object has a boundary code property
const hasBoundaryCode = obj.hasOwnProperty(boundaryCodeKey);

// Push the row to the appropriate array based on whether it has a boundary code property
if (hasBoundaryCode) {
Expand All @@ -765,7 +778,6 @@ function modifyBoundaryData(boundaryData: unknown[], localizationMap?: any) {
}



async function getDataFromSheet(request: any, fileStoreId: any, tenantId: any, createAndSearchConfig: any, optionalSheetName?: any, localizationMap?: { [key: string]: string }) {
const type = request?.body?.ResourceDetails?.type;
const fileResponse = await httpRequest(config.host.filestore + config.paths.filestore + "/url", {}, { tenantId: tenantId, fileStoreIds: fileStoreId }, "get");
Expand Down

0 comments on commit 3058897

Please sign in to comment.