Skip to content

Commit

Permalink
updated logic for target columns acc to delivery conditions only for …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
nitish-egov authored Jul 24, 2024
1 parent 4001a02 commit e01bec6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion utilities/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');


Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions utilities/project-factory/src/server/utils/targetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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: {
Expand All @@ -117,6 +116,12 @@ async function updateTargetColumnsIfDeliveryConditionsDifferForSMC(request: any)
}
}

function isDynamicTargetTemplateForProjectType(projectType: string) {
const projectTypesFromConfig = config?.enableDynamicTemplateFor;
return projectTypesFromConfig?.includes(projectType) ?? false;
}





Expand All @@ -125,4 +130,5 @@ export {
generateTargetColumnsBasedOnDeliveryConditions,
generateDynamicTargetHeaders,
updateTargetColumnsIfDeliveryConditionsDifferForSMC,
isDynamicTargetTemplateForProjectType
};
Original file line number Diff line number Diff line change
Expand Up @@ -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";



Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e01bec6

Please sign in to comment.