Skip to content

Commit

Permalink
HLM-6407 adding changes for facility template
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyanka-eGov committed Jul 23, 2024
1 parent 15ca588 commit c72c7d7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
16 changes: 11 additions & 5 deletions utilities/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import { httpRequest } from "../utils/request";
import { getFormattedStringForDebug, logger } from "../utils/logger";
import createAndSearch from '../config/createAndSearch';
import { getDataFromSheet, generateActivityMessage, throwError, translateSchema, replicateRequest } from "../utils/genericUtils";
import { getDataFromSheet, generateActivityMessage, throwError, translateSchema, replicateRequest, appendProjectTypeToCapacity } from "../utils/genericUtils";
import { immediateValidationForTargetSheet, validateSheetData, validateTargetSheetData } from '../validators/campaignValidators';
import { callMdmsTypeSchema, getCampaignNumber } from "./genericApis";
import { boundaryBulkUpload, convertToTypeData, generateHierarchy, generateProcessedFileAndPersist, getBoundaryOnWhichWeSplit, getLocalizedName, reorderBoundariesOfDataAndValidate, checkIfSourceIsMicroplan } from "../utils/campaignUtils";
Expand Down Expand Up @@ -730,7 +730,7 @@ async function performAndSaveResourceActivity(request: any, createAndSearchConfi
}
_.set(newRequestBody, createAndSearchConfig?.createBulkDetails?.createPath, chunkData);
creationTime = Date.now();
if (type == "facility") {
if (type == "facility" || type == "facilityMicroplan") {
await handeFacilityProcess(request, createAndSearchConfig, params, activities, newRequestBody);
}
else if (type == "user") {
Expand Down Expand Up @@ -847,10 +847,9 @@ async function processCreate(request: any, localizationMap?: any) {
// console.log(`Source is MICROPLAN -->`, source);
let createAndSearchConfig: any;
createAndSearchConfig = createAndSearch[type];

const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;
if (checkIfSourceIsMicroplan(source)) {
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;
logger.info(`Data create Source is MICROPLAN --> ${source}`);
if (
createAndSearchConfig &&
Expand All @@ -870,11 +869,18 @@ async function processCreate(request: any, localizationMap?: any) {

const dataFromSheet = await getDataFromSheet(request, request?.body?.ResourceDetails?.fileStoreId, request?.body?.ResourceDetails?.tenantId, createAndSearchConfig, undefined, localizationMap)
let schema: any;

if (type == "facility") {
logger.info("Fetching schema to validate the created data for type: " + type);
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, type);
schema = mdmsResponse
}
else if(type == "facilityMicroplan") {
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, "facility", "microplan", "HCM-ADMIN-CONSOLE.adminSchemaMicroplan");
schema = mdmsResponse
logger.info("Appending project type to capacity for microplan " + campaignType);
schema = await appendProjectTypeToCapacity(schema, campaignType);
}
else if (type == "user") {
logger.info("Fetching schema to validate the created data for type: " + type);
const mdmsResponse = await callMdmsTypeSchema(request, tenantId, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const createAndSearch: any = {
uniqueIdentifier: "id",
uniqueIdentifierColumn: "A",
activeColumn: "F",
activeColumnName: "HCM_ADMIN_CONSOLE_FACILITY_USAGE",
activeColumnName: "HCM_ADMIN_CONSOLE_FACILITY_USAGE_MICROPLAN",
uniqueIdentifierColumnName: "HCM_ADMIN_CONSOLE_FACILITY_CODE",
matchEachKey: true,
parseArrayConfig: {
Expand Down
46 changes: 45 additions & 1 deletion utilities/project-factory/src/server/utils/genericUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,49 @@ async function getMdmsDataBasedOnCampaignType(request: any, localizationMap?: an
}


function appendProjectTypeToCapacity(schema: any, projectType: string): any {
const updatedSchema = JSON.parse(JSON.stringify(schema)); // Deep clone the schema

const capacityKey = 'HCM_ADMIN_CONSOLE_FACILITY_CAPACITY_MICROPLAN';
const newCapacityKey = `${capacityKey}_${projectType}`;

// Update properties
if (updatedSchema.properties[capacityKey]) {
updatedSchema.properties[newCapacityKey] = {
...updatedSchema.properties[capacityKey],
name: `${updatedSchema.properties[capacityKey].name}_${projectType}`
};
delete updatedSchema.properties[capacityKey];
}

// Update required
updatedSchema.required = updatedSchema.required.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update columns
updatedSchema.columns = updatedSchema.columns.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update unique
updatedSchema.unique = updatedSchema.unique.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

// Update errorMessage
if (updatedSchema.errorMessage[capacityKey]) {
updatedSchema.errorMessage[newCapacityKey] = updatedSchema.errorMessage[capacityKey];
delete updatedSchema.errorMessage[capacityKey];
}

// Update columnsNotToBeFreezed
updatedSchema.columnsNotToBeFreezed = updatedSchema.columnsNotToBeFreezed.map((item: string) =>
item === capacityKey ? newCapacityKey : item
);

return updatedSchema;
}


export {
Expand Down Expand Up @@ -1179,7 +1222,8 @@ export {
getConfigurableColumnHeadersFromSchemaForTargetSheet,
createBoundaryDataMainSheet,
getMdmsDataBasedOnCampaignType,
shutdownGracefully
shutdownGracefully,
appendProjectTypeToCapacity
};


0 comments on commit c72c7d7

Please sign in to comment.