From e01bec696a910d0a65a1ac425f4eb8e9ac4f2791 Mon Sep 17 00:00:00 2001 From: nitish-egov <137176807+nitish-egov@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:24:54 +0530 Subject: [PATCH] updated logic for target columns acc to delivery conditions only for smc (#1137) * some changes related to generate boundary template * updated logic for making configurable target acc to delivery only for smc * refactored code for including dynamic target columns for specific types according to configs array --- .../project-factory/src/server/config/index.ts | 2 +- .../src/server/utils/campaignUtils.ts | 4 ++-- .../src/server/utils/targetUtils.ts | 14 ++++++++++---- .../src/server/validators/campaignValidators.ts | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/utilities/project-factory/src/server/config/index.ts b/utilities/project-factory/src/server/config/index.ts index 83540f022a5..417886225b9 100644 --- a/utilities/project-factory/src/server/config/index.ts +++ b/utilities/project-factory/src/server/config/index.ts @@ -16,8 +16,8 @@ const getDBSchemaName = (dbSchema = "") => { } // Configuration object containing various environment variables const config = { + enableDynamicTemplateFor: ["MR-DN"], isCallGenerateWhenDeliveryConditionsDiffer: true, - enableDynamicTargetTemplate: true, prefixForMicroplanCampaigns: "MP", excludeHierarchyTypeFromBoundaryCodes: false, excludeBoundaryNameAtLastFromBoundaryCodes: false, diff --git a/utilities/project-factory/src/server/utils/campaignUtils.ts b/utilities/project-factory/src/server/utils/campaignUtils.ts index ecefcee6c79..370c346c01d 100644 --- a/utilities/project-factory/src/server/utils/campaignUtils.ts +++ b/utilities/project-factory/src/server/utils/campaignUtils.ts @@ -19,7 +19,7 @@ import { validateBoundaryOfResouces } from "../validators/campaignValidators"; import { getExcelWorkbookFromFileURL, getNewExcelWorkbook, lockTargetFields, updateFontNameToRoboto } from "./excelUtils"; import { callGenerateIfBoundariesDiffer } from "./generateUtils"; import { createProcessTracks, persistTrack } from "./processTrackUtils"; -import { generateDynamicTargetHeaders, updateTargetColumnsIfDeliveryConditionsDifferForSMC } from "./targetUtils"; +import { generateDynamicTargetHeaders, isDynamicTargetTemplateForProjectType, updateTargetColumnsIfDeliveryConditionsDifferForSMC } from "./targetUtils"; const _ = require('lodash'); @@ -1445,7 +1445,7 @@ async function createNewSheet(request: any, workbook: any, newSheetData: any, un addDataToSheet(newSheet, newSheetData, 'F3842D', 40); let columnsNotToBeFreezed: any; const boundaryCodeColumnIndex = localizedHeaders.findIndex((header: any) => header === getLocalizedName(config?.boundary?.boundaryCode, localizationMap)); - if (campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0 && config?.enableDynamicTargetTemplate) { + if (isDynamicTargetTemplateForProjectType(campaignObject?.projectType) && campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0) { columnsNotToBeFreezed = localizedHeaders.slice(boundaryCodeColumnIndex + 1); } else { diff --git a/utilities/project-factory/src/server/utils/targetUtils.ts b/utilities/project-factory/src/server/utils/targetUtils.ts index 0ebc47aadb1..244bcd3016b 100644 --- a/utilities/project-factory/src/server/utils/targetUtils.ts +++ b/utilities/project-factory/src/server/utils/targetUtils.ts @@ -8,8 +8,7 @@ import { callGenerate } from './generateUtils'; async function generateDynamicTargetHeaders(request: any, campaignObject: any, localizationMap?: any) { const isSourceMicroplan = checkIfSourceIsMicroplan(campaignObject); let headerColumnsAfterHierarchy: any; - if (campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0 && config?.enableDynamicTargetTemplate && !isSourceMicroplan) { - + if (isDynamicTargetTemplateForProjectType(campaignObject?.projectType) && campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0 && !isSourceMicroplan) { const modifiedUniqueDeliveryConditions = modifyDeliveryConditions(campaignObject.deliveryRules); headerColumnsAfterHierarchy = generateTargetColumnsBasedOnDeliveryConditions(modifiedUniqueDeliveryConditions, localizationMap); @@ -78,7 +77,7 @@ function generateTargetColumnsBasedOnDeliveryConditions(uniqueDeliveryConditions function createTargetString(uniqueDeliveryConditionsObject: any, localizationMap?: any) { let targetString: any; - const prefix = getLocalizedName("HCM_ADMIN_CONSOLE_TARGET", localizationMap); + const prefix = getLocalizedName("HCM_ADMIN_CONSOLE_TARGET_SMC", localizationMap); const attributeCode = getLocalizedName(uniqueDeliveryConditionsObject.attribute.code.toUpperCase(), localizationMap); const operatorMessage = getLocalizedName(uniqueDeliveryConditionsObject.operator.code, localizationMap); const localizedFROM = getLocalizedName("FROM", localizationMap); @@ -94,7 +93,7 @@ function createTargetString(uniqueDeliveryConditionsObject: any, localizationMap async function updateTargetColumnsIfDeliveryConditionsDifferForSMC(request: any) { const existingCampaignDetails = request?.body?.ExistingCampaignDetails; if (existingCampaignDetails) { - if (config?.isCallGenerateWhenDeliveryConditionsDiffer && !_.isEqual(existingCampaignDetails?.deliveryRules, request?.body?.CampaignDetails?.deliveryRules)) { + if (isDynamicTargetTemplateForProjectType(request?.body?.CampaignDetails?.projectType) && config?.isCallGenerateWhenDeliveryConditionsDiffer && !_.isEqual(existingCampaignDetails?.deliveryRules, request?.body?.CampaignDetails?.deliveryRules)) { const newRequestBody = { RequestInfo: request?.body?.RequestInfo, Filters: { @@ -117,6 +116,12 @@ async function updateTargetColumnsIfDeliveryConditionsDifferForSMC(request: any) } } +function isDynamicTargetTemplateForProjectType(projectType: string) { + const projectTypesFromConfig = config?.enableDynamicTemplateFor; + return projectTypesFromConfig?.includes(projectType) ?? false; +} + + @@ -125,4 +130,5 @@ export { generateTargetColumnsBasedOnDeliveryConditions, generateDynamicTargetHeaders, updateTargetColumnsIfDeliveryConditionsDifferForSMC, + isDynamicTargetTemplateForProjectType }; diff --git a/utilities/project-factory/src/server/validators/campaignValidators.ts b/utilities/project-factory/src/server/validators/campaignValidators.ts index 87f1459ed8d..8c50b9bcd46 100644 --- a/utilities/project-factory/src/server/validators/campaignValidators.ts +++ b/utilities/project-factory/src/server/validators/campaignValidators.ts @@ -20,7 +20,7 @@ import { searchProjectTypeCampaignService } from "../service/campaignManageServi import { campaignStatuses, resourceDataStatuses } from "../config/constants"; import { getBoundaryColumnName, getBoundaryTabName } from "../utils/boundaryUtils"; import addAjvErrors from "ajv-errors"; -import { generateTargetColumnsBasedOnDeliveryConditions, modifyDeliveryConditions } from "../utils/targetUtils"; +import { generateTargetColumnsBasedOnDeliveryConditions, isDynamicTargetTemplateForProjectType, modifyDeliveryConditions } from "../utils/targetUtils"; @@ -220,7 +220,7 @@ async function validateTargets(request: any, data: any[], errors: any[], localiz let columnsToValidate: any; const responseFromCampaignSearch = await getCampaignSearchResponse(request); const campaignObject = responseFromCampaignSearch?.CampaignDetails?.[0]; - if (campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0 && config?.enableDynamicTargetTemplate) { + if (isDynamicTargetTemplateForProjectType(campaignObject?.projectType) && campaignObject.deliveryRules && campaignObject.deliveryRules.length > 0) { const modifiedUniqueDeliveryConditions = modifyDeliveryConditions(campaignObject.deliveryRules); columnsToValidate = generateTargetColumnsBasedOnDeliveryConditions(modifiedUniqueDeliveryConditions, localizationMap);