diff --git a/health-services/project-factory/src/server/config/index.ts b/health-services/project-factory/src/server/config/index.ts index 862ac0a905..c0608bf833 100644 --- a/health-services/project-factory/src/server/config/index.ts +++ b/health-services/project-factory/src/server/config/index.ts @@ -17,8 +17,9 @@ const getDBSchemaName = (dbSchema = "") => { } // Configuration object containing various environment variables const config = { - batchSize:100, + batchSize: 100, cacheTime: 300, + coDeliveryCampaign: "Co-delivery", isProduction: process.env ? true : false, token: "", // add default token if core services are not port forwarded enableDynamicTemplateFor: process.env.ENABLE_DYNAMIC_TEMPLATE_FOR || "", diff --git a/health-services/project-factory/src/server/validators/campaignValidators.ts b/health-services/project-factory/src/server/validators/campaignValidators.ts index 50271de76c..b8e235a085 100644 --- a/health-services/project-factory/src/server/validators/campaignValidators.ts +++ b/health-services/project-factory/src/server/validators/campaignValidators.ts @@ -88,13 +88,27 @@ async function fetchBoundariesFromCampaignDetails(request: any) { return responseBoundaries; } -function validateTargetForNormalCampaigns(data: any, errors: any, localizedTargetColumnNames: any, localizationMap?: { [key: string]: string }) { +const getPresentTargetColumns = ( + campaignType: string, + boundaryData: any[], + localizedTargetColumnNames: string[] +): string[] => { + if (campaignType === config?.coDeliveryCampaign) { + return localizedTargetColumnNames.filter((column: string) => + boundaryData.some((row: any) => row.hasOwnProperty(column)) + ); + } + return localizedTargetColumnNames; +}; + +function validateTargetForNormalCampaigns(data: any, errors: any, localizedTargetColumnNames: any, localizationMap?: { [key: string]: string }, campaignType?: any) { for (const key in data) { if (key !== getLocalizedName(getBoundaryTabName(), localizationMap) && key !== getLocalizedName(config.values?.readMeTab, localizationMap)) { if (Array.isArray(data[key])) { const boundaryData = data[key]; + const presentTargetColumns = getPresentTargetColumns(campaignType, boundaryData, localizedTargetColumnNames); boundaryData.forEach((obj: any, index: number) => { - for (const targetColumn of localizedTargetColumnNames) { + for (const targetColumn of presentTargetColumns) { const target = obj[targetColumn]; if (!target) { errors.push({ @@ -155,7 +169,7 @@ async function validateTargets(request: any, data: any[], errors: any[], localiz validateLatLongForMicroplanCampaigns(data, errors, localizationMap); } else { - validateTargetForNormalCampaigns(data, errors, localizedTargetColumnNames, localizationMap); + validateTargetForNormalCampaigns(data, errors, localizedTargetColumnNames, localizationMap, campaignObject?.projectType); } }