Skip to content

Commit

Permalink
Feat : added active inactive boundary check (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-egov authored Jun 10, 2024
1 parent e46068b commit ad8197c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
const columnsForGivenCampaignId = mdmsResponse?.mdms[0]?.data?.properties?.stringProperties;

// Sort the columns array based on the order number
columnsForGivenCampaignId?.sort((columnA:any, columnB:any) => columnA.orderNumber - columnB.orderNumber);
columnsForGivenCampaignId?.sort((columnA: any, columnB: any) => columnA.orderNumber - columnB.orderNumber);

// Extract the names of columns and insert them into an array
const sortedColumnNames = columnsForGivenCampaignId?.map((column: any) => column.name);
Expand All @@ -1733,6 +1733,7 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
}
return headerColumnsAfterHierarchy;
} catch (error: any) {
console.log(error)
throwError("FILE", 400, "FETCHING_COLUMN_ERROR", "Error fetching column Headers From Schema (either boundary code column not found or given Campaign Type not found in schema) Check logs")
}

Expand Down
9 changes: 6 additions & 3 deletions utilities/project-factory/src/server/utils/excelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ function lockTargetFields(newSheet: any, targetColumnNumber: any, boundaryCodeCo
});
// Unlock cells in the target column
if (targetColumnNumber > -1) {
newSheet.eachRow((row: any) => {
const cell = row.getCell(targetColumnNumber); // Excel columns are 1-based
cell.protection = { locked: false };
newSheet.eachRow({ includeEmpty: true }, (row: any, rowNumber: number) => {
// Skip the first row
if (rowNumber > 1) {
const cell = row.getCell(targetColumnNumber); // Excel columns are 1-based
cell.protection = { locked: false };
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ async function validateUniqueBoundaries(uniqueBoundaries: any[], request: any) {



async function validateBoundaryData(data: any[], request: any, boundaryColumn: any) {
async function validateBoundaryData(data: any[], request: any, boundaryColumn: any, localizationMap: any) {
const boundarySet = new Set(); // Create a Set to store unique boundaries
logger.info("validating for the boundary data")
data.forEach((element, index) => {
const activeColumnName = createAndSearch?.[request?.body?.ResourceDetails?.type]?.activeColumnName ? getLocalizedName(createAndSearch?.[request?.body?.ResourceDetails?.type]?.activeColumnName, localizationMap) : null;
const uniqueIdentifierColumnName = createAndSearch?.[request?.body?.ResourceDetails?.type]?.uniqueIdentifierColumnName ? getLocalizedName(createAndSearch?.[request?.body?.ResourceDetails?.type]?.uniqueIdentifierColumnName, localizationMap) : null;
if (activeColumnName && uniqueIdentifierColumnName) {
data = data.filter((item: any) => item[activeColumnName] === "Active" || !item[uniqueIdentifierColumnName]);
data.forEach((item: any) => item[activeColumnName] = "Active");
}
data.forEach((element) => {
const boundaries = element[boundaryColumn];
if (!boundaries) {
throwError("COMMON", 400, "VALIDATION_ERROR", `Boundary Code is required for element in rowNumber ${element['!row#number!']}`);
Expand Down Expand Up @@ -310,12 +316,14 @@ async function validateViaSchema(data: any, schema: any, request: any, localizat
const validate = ajv.compile(schema);
const validationErrors: any[] = [];
const uniqueIdentifierColumnName = getLocalizedName(createAndSearch?.[request?.body?.ResourceDetails?.type]?.uniqueIdentifierColumnName, localizationMap)
const activeColumnName = createAndSearch?.[request?.body?.ResourceDetails?.type]?.activeColumnName ? getLocalizedName(createAndSearch?.[request?.body?.ResourceDetails?.type]?.activeColumnName, localizationMap) : null;
if (request?.body?.ResourceDetails?.type == "user") {
validatePhoneNumber(data)
}
if (data?.length > 0) {
data.forEach((item: any) => {
if (!item?.[uniqueIdentifierColumnName])
const active = activeColumnName ? item[activeColumnName] : "Active";
if (active == "Active" || !item?.[uniqueIdentifierColumnName])
if (!validate(item)) {
validationErrors.push({ index: item?.["!row#number!"], errors: validate.errors });
}
Expand Down Expand Up @@ -352,7 +360,7 @@ async function validateSheetData(data: any, request: any, schema: any, boundaryV
await validateViaSchema(data, schema, request, localizationMap);
if (boundaryValidation) {
const localisedBoundaryCode = getLocalizedName(boundaryValidation?.column, localizationMap)
await validateBoundaryData(data, request, localisedBoundaryCode);
await validateBoundaryData(data, request, localisedBoundaryCode, localizationMap);
}
}

Expand Down Expand Up @@ -633,9 +641,16 @@ async function validateBoundariesForTabs(CampaignDetails: any, resource: any, re

// Initialize resource boundary codes as a set for uniqueness
const resourceBoundaryCodesArray: any[] = [];
var activeColumnName: any = null;
if (createAndSearch?.[resource.type]?.activeColumn && createAndSearch?.[resource.type]?.activeColumnName) {
activeColumnName = getLocalizedName(createAndSearch?.[resource.type]?.activeColumn, localizationMap);
}
datas.forEach((data: any) => {
const codes = data?.[boundaryColumn]?.split(',').map((code: string) => code.trim()) || [];
resourceBoundaryCodesArray.push({ boundaryCodes: codes, rowNumber: data?.['!row#number!'] })
var active = activeColumnName ? data?.[activeColumnName] : "Active";
if (active == "Active") {
resourceBoundaryCodesArray.push({ boundaryCodes: codes, rowNumber: data?.['!row#number!'] })
}
});

// Convert sets to arrays for comparison
Expand Down

0 comments on commit ad8197c

Please sign in to comment.