Skip to content
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

target generate and validate for Co-delivery #1294

Open
wants to merge 1 commit into
base: console
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this ?

by default if you run this for all campaign types whta will happen ?

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

Expand Down
Loading