Skip to content

Commit

Permalink
Merge branch 'console' into console-v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Nov 28, 2024
2 parents 6301f0e + 074342d commit 7577e60
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 353 deletions.
11 changes: 3 additions & 8 deletions health-services/project-factory/src/server/api/campaignApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1966,21 +1966,16 @@ const getHeadersOfBoundarySheet = async (
async function getCampaignSearchResponse(request: any) {
try {
logger.info(`searching for campaign details`);
const requestInfo = { RequestInfo: request?.body?.RequestInfo };
const campaignDetails = {
CampaignDetails: {
const CampaignDetails = {
tenantId:
request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId,
ids: [
request?.query?.campaignId ||
request?.body?.ResourceDetails?.campaignId,
],
},
};
const requestBody = { ...requestInfo, ...campaignDetails };
const req: any = replicateRequest(request, requestBody);
}
const projectTypeSearchResponse: any =
await searchProjectTypeCampaignService(req);
await searchProjectTypeCampaignService(CampaignDetails);
return projectTypeSearchResponse;
} catch (error: any) {
logger.error(
Expand Down
65 changes: 63 additions & 2 deletions health-services/project-factory/src/server/api/genericApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ async function getBoundarySheetData(
}

if (request?.query?.type === "boundaryManagement" || request?.query?.type === 'boundaryGeometryManagement') {
headerColumnsAfterHierarchy = getLocalizedHeaders(["HCM_ADMIN_CONSOLE_BOUNDARY_CODE", "HCM_ADMIN_CONSOLE_LAT", "HCM_ADMIN_CONSOLE_LONG"], localizationMap);
headerColumnsAfterHierarchy = await getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement(request, localizationMap);
}
const headers = [...localizedHeadersUptoHierarchy, ...headerColumnsAfterHierarchy];
// create empty sheet if no boundary present in system
Expand Down Expand Up @@ -839,6 +839,66 @@ async function getBoundarySheetData(
}
}

async function getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement(request:any, localizationMap?: { [key: string]: string }) {
try {
const mdmsResponse = await callMdmsTypeSchema(
request,
request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId,
false,
request?.query?.type || request?.body?.ResourceDetails?.type,
"all"
);
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
logger.error(
`Campaign Type all has not any columns configured in schema`
);
throwError(
"COMMON",
400,
"SCHEMA_ERROR",
`Campaign Type all has not any columns configured in schema`
);
}
// Extract columns from the response
const columnsForGivenCampaignId = mdmsResponse?.columns;

// Get localized headers based on the column names
const headerColumnsAfterHierarchy = getLocalizedHeaders(
columnsForGivenCampaignId,
localizationMap
);
if (
!headerColumnsAfterHierarchy.includes(
getLocalizedName(config.boundary.boundaryCode, localizationMap)
)
) {
logger.error(
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
);
throwError(
"COMMON",
400,
"VALIDATION_ERROR",
`Column Headers of generated Boundary Template does not have ${getLocalizedName(
config.boundary.boundaryCode,
localizationMap
)} column`
);
}
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"
);
}
}
async function createStaff(resouceBody: any) {
// Create staff
const staffCreateUrl =
Expand Down Expand Up @@ -1403,5 +1463,6 @@ export {
getSheetDataFromWorksheet,
createStaffHelper,
createProjectFacilityHelper, createProjectResourceHelper,
createAndUploadJsonFile
createAndUploadJsonFile,
getConfigurableColumnHeadersBasedOnCampaignTypeForBoundaryManagement
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as express from "express";
import { createCampaignService, createProjectTypeCampaignService, fetchFromMicroplanService, retryProjectTypeCampaignService, searchProcessTracksService, searchProjectTypeCampaignService, updateProjectTypeCampaignService } from "../../service/campaignManageService";
import { logger } from "../../utils/logger";
import { errorResponder, sendResponse } from "../../utils/genericUtils";
import { validateSearchProjectCampaignRequest } from "../../validators/campaignValidators";



Expand Down Expand Up @@ -82,7 +83,9 @@ class campaignManageController {
) => {
try {
logger.info("RECEIVED A PROJECT TYPE SEARCH REQUEST");
const responseBody = await searchProjectTypeCampaignService(request);
// Validate the search request for project type campaigns
await validateSearchProjectCampaignRequest(request);
const responseBody = await searchProjectTypeCampaignService(request?.body?.CampaignDetails);
// Send response with campaign details and total count
return sendResponse(response, responseBody, request);
} catch (e: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from "express";
import { processBasedOnAction, processFetchMicroPlan, searchProjectCampaignResourcData, updateCampaign } from "../utils/campaignUtils";
import { processBasedOnAction, processFetchMicroPlan, searchProjectCampaignResourcData, updateCampaignAfterSearch } from "../utils/campaignUtils";
import { logger } from "../utils/logger";
import { validateMicroplanRequest, validateProjectCampaignRequest, validateSearchProcessTracksRequest, validateSearchProjectCampaignRequest } from "../validators/campaignValidators";
import { validateMicroplanRequest, validateProjectCampaignRequest, validateSearchProcessTracksRequest } from "../validators/campaignValidators";
import { validateCampaignRequest } from "../validators/genericValidator";
import { createRelatedResouce } from "../api/genericApis";
import { enrichCampaign } from "../api/campaignApis";
Expand All @@ -28,16 +28,14 @@ async function updateProjectTypeCampaignService(request: express.Request) {
return request?.body?.CampaignDetails;
}

async function searchProjectTypeCampaignService(
request: express.Request,
async function searchProjectTypeCampaignService(campaignDetails: any
) {
// Validate the search request for project type campaigns
await validateSearchProjectCampaignRequest(request);
// await validateSearchProjectCampaignRequest(request);
logger.info("VALIDATED THE PROJECT TYPE SEARCH REQUEST");

// Search for project campaign resource data
await searchProjectCampaignResourcData(request);
const responseBody: any = { CampaignDetails: request?.body?.CampaignDetails, totalCount: request?.body?.totalCount }
const { responseData, totalCount } = await searchProjectCampaignResourcData(campaignDetails);
const responseBody: any = { CampaignDetails: responseData, totalCount: totalCount }
return responseBody;
};

Expand Down Expand Up @@ -83,8 +81,8 @@ async function fetchFromMicroplanService(request: express.Request) {
logger.info("FETCHING DATA FROM MICROPLAN");
await validateMicroplanRequest(request);
logger.info("Update Campaign Object")
await updateCampaign(request ,"MICROPLAN_FETCHING")
logger.info("Validated request successfully");
await updateCampaignAfterSearch(request, "MICROPLAN_FETCHING")
logger.info("Validated request successfully");
processFetchMicroPlan(request);
return request.body.CampaignDetails;
}
Expand Down
Loading

0 comments on commit 7577e60

Please sign in to comment.