-
Notifications
You must be signed in to change notification settings - Fork 0
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
Microplan check #1
base: console
Are you sure you want to change the base?
Changes from 5 commits
c962668
fe80382
aa38de5
083df47
012cffd
b73ef10
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -93,7 +93,7 @@ import { | |||||||||
modifyNewSheetData, | ||||||||||
unhideColumnsOfProcessedFile, | ||||||||||
} from "./onGoingCampaignUpdateUtils"; | ||||||||||
import { changeCreateDataForMicroplan, lockSheet } from "./microplanUtils"; | ||||||||||
import { changeCreateDataForMicroplan, isMicroplanRequest, isMicroplanCampaignId, lockSheet } from "./microplanUtils"; | ||||||||||
const _ = require("lodash"); | ||||||||||
import { searchDataService } from "../service/dataManageService"; | ||||||||||
import { searchMDMSDataViaV2Api } from "../api/coreApis"; | ||||||||||
|
@@ -305,15 +305,15 @@ function enrichActiveAndUUidColumn( | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
function deterMineLastColumnAndEnrichUserDetails( | ||||||||||
async function deterMineLastColumnAndEnrichUserDetails( | ||||||||||
ashish-egov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
worksheet: any, | ||||||||||
errorDetailsColumn: number, | ||||||||||
userNameAndPassword: | ||||||||||
| { rowNumber: number; userName: string; password: string }[] | ||||||||||
| undefined, | ||||||||||
request: any, | ||||||||||
createAndSearchConfig: { uniqueIdentifierColumn?: number } | ||||||||||
): string { | ||||||||||
){ | ||||||||||
// Determine the last column | ||||||||||
let lastColumn: any = errorDetailsColumn; | ||||||||||
if (createAndSearchConfig?.uniqueIdentifierColumn !== undefined) { | ||||||||||
|
@@ -329,7 +329,7 @@ function deterMineLastColumnAndEnrichUserDetails( | |||||||||
|
||||||||||
// Update columns if the request indicates a different source | ||||||||||
if ( | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
) { | ||||||||||
usernameColumn = "F"; | ||||||||||
passwordColumn = "G"; | ||||||||||
|
@@ -387,7 +387,7 @@ function adjustRef(worksheet: any, lastColumn: any) { | |||||||||
}; | ||||||||||
} | ||||||||||
|
||||||||||
function processErrorData( | ||||||||||
async function processErrorData( | ||||||||||
request: any, | ||||||||||
createAndSearchConfig: any, | ||||||||||
workbook: any, | ||||||||||
|
@@ -418,7 +418,7 @@ function processErrorData( | |||||||||
: additionalDetailsErrors; | ||||||||||
|
||||||||||
// Determine the last column to set the worksheet ref | ||||||||||
const lastColumn = deterMineLastColumnAndEnrichUserDetails( | ||||||||||
const lastColumn = await deterMineLastColumnAndEnrichUserDetails( | ||||||||||
worksheet, | ||||||||||
errorDetailsColumn, | ||||||||||
userNameAndPassword, | ||||||||||
|
@@ -535,7 +535,7 @@ async function updateStatusFile( | |||||||||
"get" | ||||||||||
); | ||||||||||
const isLockSheetNeeded = | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
? true | ||||||||||
: false; | ||||||||||
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. 🛠️ Refactor suggestion Simplify boolean assignment by removing unnecessary ternary operator. The ternary operator is redundant since Apply this diff: - const isLockSheetNeeded =
- await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId)
- ? true
- : false;
+ const isLockSheetNeeded = await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId); 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 538-540: Unnecessary use of boolean literals in conditional expression. Simplify your code by directly assigning the result without using a ternary operator. (lint/complexity/noUselessTernary) |
||||||||||
|
||||||||||
|
@@ -554,7 +554,7 @@ async function updateStatusFile( | |||||||||
const columnsToUnhide = ["G", "H", "J", "K"]; | ||||||||||
unhideColumnsOfProcessedFile(worksheet, columnsToUnhide); | ||||||||||
} | ||||||||||
processErrorData( | ||||||||||
await processErrorData( | ||||||||||
request, | ||||||||||
createAndSearchConfig, | ||||||||||
workbook, | ||||||||||
|
@@ -595,7 +595,7 @@ async function updateStatusFileForEachSheets( | |||||||||
"get" | ||||||||||
); | ||||||||||
const isLockSheetNeeded = | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
? true | ||||||||||
: false; | ||||||||||
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. 🛠️ Refactor suggestion Simplify boolean assignment by removing unnecessary ternary operator. Similar to the previous instance, remove the redundant ternary operator. Apply this diff: - const isLockSheetNeeded =
- await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId)
- ? true
- : false;
+ const isLockSheetNeeded = await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId); 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 598-600: Unnecessary use of boolean literals in conditional expression. Simplify your code by directly assigning the result without using a ternary operator. (lint/complexity/noUselessTernary) |
||||||||||
|
||||||||||
|
@@ -702,7 +702,7 @@ async function processData( | |||||||||
const requiresToSearchFromSheet = | ||||||||||
createAndSearchConfig?.requiresToSearchFromSheet; | ||||||||||
const isSourceMicroplan = | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan"; | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId); | ||||||||||
var createData = [], | ||||||||||
searchData = []; | ||||||||||
for (const data of dataFromSheet) { | ||||||||||
|
@@ -810,7 +810,7 @@ async function generateProcessedFileAndPersist( | |||||||||
) { | ||||||||||
if ( | ||||||||||
request.body.ResourceDetails.type == "boundaryWithTarget" || | ||||||||||
(request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" && | ||||||||||
(await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) && | ||||||||||
request.body.ResourceDetails.type == "user") | ||||||||||
) { | ||||||||||
await updateStatusFileForEachSheets(request, localizationMap); | ||||||||||
|
@@ -838,7 +838,7 @@ async function generateProcessedFileAndPersist( | |||||||||
...request?.body?.ResourceDetails?.additionalDetails, | ||||||||||
sheetErrors: request?.body?.additionalDetailsErrors, | ||||||||||
source: | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
? "microplan" | ||||||||||
: null, | ||||||||||
}, | ||||||||||
|
@@ -881,7 +881,7 @@ async function generateProcessedFileAndPersist( | |||||||||
if (request?.body?.ResourceDetails?.action == "create") { | ||||||||||
persistMessage.ResourceDetails.additionalDetails = { | ||||||||||
source: | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == "microplan" | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
? "microplan" | ||||||||||
: null, | ||||||||||
fileName: | ||||||||||
|
@@ -2484,7 +2484,6 @@ async function appendSheetsToWorkbook( | |||||||||
); | ||||||||||
const responseFromCampaignSearch = await getCampaignSearchResponse(request); | ||||||||||
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0]; | ||||||||||
// const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); | ||||||||||
const mainSheet = workbook.addWorksheet( | ||||||||||
getLocalizedName(getBoundaryTabName(), localizationMap) | ||||||||||
); | ||||||||||
|
@@ -2973,16 +2972,15 @@ async function updateAndPersistResourceDetails( | |||||||||
lastModifiedTime: Date.now(), | ||||||||||
}, | ||||||||||
additionalDetails: | ||||||||||
{ | ||||||||||
...request?.body?.ResourceDetails?.additionalDetails, | ||||||||||
sheetErrors: request?.body?.additionalDetailsErrors, | ||||||||||
source: | ||||||||||
request?.body?.ResourceDetails?.additionalDetails?.source == | ||||||||||
"microplan" | ||||||||||
? "microplan" | ||||||||||
: null, | ||||||||||
[name]: [fileStoreId], | ||||||||||
}, | ||||||||||
{ | ||||||||||
...request?.body?.ResourceDetails?.additionalDetails, | ||||||||||
sheetErrors: request?.body?.additionalDetailsErrors, | ||||||||||
source: | ||||||||||
await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId) | ||||||||||
? "microplan" | ||||||||||
: null, | ||||||||||
[name]: [fileStoreId], | ||||||||||
} , | ||||||||||
}; | ||||||||||
} else { | ||||||||||
request.body.ResourceDetails = { | ||||||||||
|
@@ -3441,7 +3439,7 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async ( | |||||||||
const responseFromCampaignSearch = await getCampaignSearchResponse(request); | ||||||||||
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0]; | ||||||||||
let campaignType = campaignObject?.projectType; | ||||||||||
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); | ||||||||||
const isSourceMicroplan = await isMicroplanRequest(request); | ||||||||||
campaignType = isSourceMicroplan | ||||||||||
? `${config?.prefixForMicroplanCampaigns}-${campaignType}` | ||||||||||
: campaignType; | ||||||||||
|
@@ -3523,7 +3521,7 @@ async function getFinalValidHeadersForTargetSheetAsPerCampaignType( | |||||||||
); | ||||||||||
const responseFromCampaignSearch = await getCampaignSearchResponse(request); | ||||||||||
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0]; | ||||||||||
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); | ||||||||||
const isSourceMicroplan = await isMicroplanRequest(request); | ||||||||||
var expectedHeadersForTargetSheetUptoHierarchy: any; | ||||||||||
if (isSourceMicroplan) { | ||||||||||
expectedHeadersForTargetSheetUptoHierarchy = localizedHierarchy; | ||||||||||
|
@@ -3630,10 +3628,6 @@ async function getBoundaryOnWhichWeSplit(request: any, tenantId: any) { | |||||||||
return mdmsResponse?.mdms?.[0]?.data?.splitBoundariesOn; | ||||||||||
} | ||||||||||
|
||||||||||
function checkIfSourceIsMicroplan(objectWithAdditionalDetails: any): boolean { | ||||||||||
return objectWithAdditionalDetails?.additionalDetails?.source === "microplan"; | ||||||||||
} | ||||||||||
|
||||||||||
function createIdRequests(employees: any[]): any[] { | ||||||||||
if (employees && Array.isArray(employees) && employees.length > 0) { | ||||||||||
const { tenantId } = employees[0]; // Assuming all employees have the same tenantId | ||||||||||
|
@@ -3782,7 +3776,6 @@ export { | |||||||||
getConfigurableColumnHeadersBasedOnCampaignType, | ||||||||||
getFinalValidHeadersForTargetSheetAsPerCampaignType, | ||||||||||
getDifferentTabGeneratedBasedOnConfig, | ||||||||||
checkIfSourceIsMicroplan, | ||||||||||
getBoundaryOnWhichWeSplit, | ||||||||||
createIdRequests, | ||||||||||
createUniqueUserNameViaIdGen, | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { produceModifiedMessages } from "../kafka/Producer"; | |
import { generateHierarchyList, getAllFacilities, getCampaignSearchResponse, getHierarchy } from "../api/campaignApis"; | ||
import { getBoundarySheetData, getSheetData, createAndUploadFile, createExcelSheet, getTargetSheetData, callMdmsData, callMdmsTypeSchema, getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement } from "../api/genericApis"; | ||
import { logger } from "./logger"; | ||
import { checkIfSourceIsMicroplan, getConfigurableColumnHeadersBasedOnCampaignType, getDifferentTabGeneratedBasedOnConfig, getLocalizedName } from "./campaignUtils"; | ||
import { getConfigurableColumnHeadersBasedOnCampaignType, getDifferentTabGeneratedBasedOnConfig, getLocalizedName } from "./campaignUtils"; | ||
import Localisation from "../controllers/localisationController/localisation.controller"; | ||
import { executeQuery } from "./db"; | ||
import { generatedResourceTransformer } from "./transforms/searchResponseConstructor"; | ||
|
@@ -18,7 +18,7 @@ import { addDataToSheet, formatWorksheet, getNewExcelWorkbook, updateFontNameToR | |
import createAndSearch from "../config/createAndSearch"; | ||
import { generateDynamicTargetHeaders } from "./targetUtils"; | ||
import { buildSearchCriteria, checkAndGiveIfParentCampaignAvailable, fetchFileUrls, getCreatedResourceIds, modifyProcessedSheetData } from "./onGoingCampaignUpdateUtils"; | ||
import { getReadMeConfigForMicroplan, getRolesForMicroplan, getUserDataFromMicroplanSheet, isMicroplanRequest, modifyBoundaryIfSourceMicroplan } from "./microplanUtils"; | ||
import { getReadMeConfigForMicroplan, getRolesForMicroplan, getUserDataFromMicroplanSheet, isMicroplanRequest, isMicroplanCampaignId, modifyBoundaryIfSourceMicroplan } from "./microplanUtils"; | ||
const NodeCache = require("node-cache"); | ||
|
||
const updateGeneratedResourceTopic = config?.kafka?.KAFKA_UPDATE_GENERATED_RESOURCE_DETAILS_TOPIC; | ||
|
@@ -544,7 +544,7 @@ async function getSchemaBasedOnSource(request: any, isSourceMicroplan: boolean, | |
|
||
async function createFacilitySheet(request: any, allFacilities: any[], localizationMap?: { [key: string]: string }) { | ||
const responseFromCampaignSearch = await getCampaignSearchResponse(request); | ||
const isSourceMicroplan = checkIfSourceIsMicroplan(responseFromCampaignSearch?.CampaignDetails?.[0]); | ||
const isSourceMicroplan = await isMicroplanCampaignId(request?.query?.campaignId); | ||
request.body.isSourceMicroplan = isSourceMicroplan; | ||
let schema: any = await getSchemaBasedOnSource(request, isSourceMicroplan, responseFromCampaignSearch?.CampaignDetails?.[0]?.additionalDetails?.resourceDistributionStrategy); | ||
Comment on lines
+547
to
549
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. 🧹 Nitpick (assertive) Consider adding error handling for microplan campaign ID check While the implementation is correct, consider adding try-catch block to handle potential errors during the microplan campaign ID check. - const isSourceMicroplan = await isMicroplanCampaignId(request?.query?.campaignId);
+ let isSourceMicroplan = false;
+ try {
+ isSourceMicroplan = await isMicroplanCampaignId(request?.query?.campaignId);
+ } catch (error) {
+ logger.error(`Error checking microplan campaign ID: ${error}`);
+ throw error;
+ }
🧰 Tools🪛 Biome (1.9.4)[error] 549-549: This let declares a variable that is only assigned once. 'schema' is never reassigned. Safe fix: Use const instead. (lint/style/useConst) |
||
const keys = schema?.columns; | ||
|
@@ -1232,7 +1232,7 @@ async function getDataFromSheetFromNormalCampaign(type: any, fileStoreId: any, t | |
|
||
|
||
async function getDataFromSheet(request: any, fileStoreId: any, tenantId: any, createAndSearchConfig: any, optionalSheetName?: any, localizationMap?: { [key: string]: string }) { | ||
const isSourceMicroplan = request?.body?.ResourceDetails?.additionalDetails?.source == "microplan"; | ||
const isSourceMicroplan = await isMicroplanCampaignId(request?.body?.ResourceDetails?.campaignId); | ||
const type = request?.body?.ResourceDetails?.type; | ||
if (isSourceMicroplan) { | ||
if (type == 'user') { | ||
|
@@ -1431,7 +1431,7 @@ function getDifferentDistrictTabs(boundaryData: any, differentTabsBasedOnLevel: | |
async function getConfigurableColumnHeadersFromSchemaForTargetSheet(request: any, hierarchy: any, boundaryData: any, differentTabsBasedOnLevel: any, campaignObject: any, localizationMap?: any) { | ||
const districtIndex = hierarchy.indexOf(differentTabsBasedOnLevel); | ||
let headers: any; | ||
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); | ||
const isSourceMicroplan = await isMicroplanRequest(request); | ||
if (isSourceMicroplan) { | ||
logger.info(`Source is Microplan.`); | ||
headers = getLocalizedHeaders(hierarchy, localizationMap); | ||
|
@@ -1450,7 +1450,7 @@ async function getMdmsDataBasedOnCampaignType(request: any, localizationMap?: an | |
const responseFromCampaignSearch = await getCampaignSearchResponse(request); | ||
const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0]; | ||
let campaignType = campaignObject.projectType; | ||
const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); | ||
const isSourceMicroplan = await isMicroplanRequest(request); | ||
campaignType = (isSourceMicroplan) ? `${config?.prefixForMicroplanCampaigns}-${campaignType}` : campaignType; | ||
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, false, request?.query?.type || request?.body?.ResourceDetails?.type, campaignType) | ||
ashish-egov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return mdmsResponse; | ||
|
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.
🧹 Nitpick (assertive)
Consider caching the result of
isMicroplanCampaignId
.The function
isMicroplanCampaignId
is called and awaited multiple times with the samecampaignId
. Since thecampaignId
does not change during the request processing, consider caching the result to reduce unnecessary asynchronous calls and improve performance.Apply this diff to cache the result:
Also applies to: 861-862, 890-890, 1017-1017, 1033-1033, 1504-1504, 1575-1575, 1644-1644, 2979-2980, 3442-3442