From c72c7d7df7bca9902aada00723e0a0095d6624b6 Mon Sep 17 00:00:00 2001 From: Priyanka-eGov Date: Mon, 22 Jul 2024 17:05:38 +0530 Subject: [PATCH] HLM-6407 adding changes for facility template --- .../src/server/api/campaignApis.ts | 16 +++++-- .../src/server/config/createAndSearch.ts | 2 +- .../src/server/utils/genericUtils.ts | 46 ++++++++++++++++++- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/utilities/project-factory/src/server/api/campaignApis.ts b/utilities/project-factory/src/server/api/campaignApis.ts index 439af9774a0..b33d4e3c354 100644 --- a/utilities/project-factory/src/server/api/campaignApis.ts +++ b/utilities/project-factory/src/server/api/campaignApis.ts @@ -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"; @@ -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") { @@ -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 && @@ -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); diff --git a/utilities/project-factory/src/server/config/createAndSearch.ts b/utilities/project-factory/src/server/config/createAndSearch.ts index c29bb90fc57..8fb63b1be9f 100644 --- a/utilities/project-factory/src/server/config/createAndSearch.ts +++ b/utilities/project-factory/src/server/config/createAndSearch.ts @@ -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: { diff --git a/utilities/project-factory/src/server/utils/genericUtils.ts b/utilities/project-factory/src/server/utils/genericUtils.ts index 3b65b766aa1..aa38c8c60b3 100644 --- a/utilities/project-factory/src/server/utils/genericUtils.ts +++ b/utilities/project-factory/src/server/utils/genericUtils.ts @@ -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 { @@ -1179,7 +1222,8 @@ export { getConfigurableColumnHeadersFromSchemaForTargetSheet, createBoundaryDataMainSheet, getMdmsDataBasedOnCampaignType, - shutdownGracefully + shutdownGracefully, + appendProjectTypeToCapacity };