new login screen added

This commit is contained in:
laxman h 2026-04-22 18:25:47 +05:30
parent bfef307725
commit d6426f705b

View File

@ -29,6 +29,11 @@ const findDistrictByName = async (districtName: string, stateName?: string) => {
}); });
}; };
const toTitleCase = (str: string) => {
if (!str) return str;
return str.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
};
export const submitApplication = async (req: AuthRequest, res: Response) => { export const submitApplication = async (req: AuthRequest, res: Response) => {
try { try {
const { const {
@ -57,6 +62,8 @@ export const submitApplication = async (req: AuthRequest, res: Response) => {
const applicationId = NomenclatureService.generateApplicationId(); const applicationId = NomenclatureService.generateApplicationId();
let districtId = null; let districtId = null;
// Normalize incoming ID sources for robustness
const incomingLocationId = req.body.locationId || req.body.districtId;
// Primary Mapping: Resolve district by Name (State + District combination) // Primary Mapping: Resolve district by Name (State + District combination)
// This is robust for external sources where ID mapping is difficult. // This is robust for external sources where ID mapping is difficult.
@ -67,16 +74,36 @@ export const submitApplication = async (req: AuthRequest, res: Response) => {
} }
} }
// Secondary Fallback: If ID is explicitly provided (Legacy/Internal use) // Secondary Fallback: If ID is explicitly provided
if (!districtId && req.body.districtId) { if (!districtId && incomingLocationId) {
const selectedDistrict = await District.findByPk(req.body.districtId); const selectedDistrict = await District.findByPk(incomingLocationId);
if (selectedDistrict) { if (selectedDistrict) {
districtId = selectedDistrict.id; districtId = selectedDistrict.id;
} }
} }
let activeOpportunityId = null; let activeOpportunityId = null;
if (districtId) {
// CASE 1: Explicit Opportunity ID provided (Trust but verify active status)
if (opportunityId) {
const explicitOpp = await Opportunity.findOne({
where: {
id: opportunityId,
status: 'active',
[Op.or]: [
{ openTo: null },
{ openTo: { [Op.gte]: new Date() } }
]
}
});
if (explicitOpp) {
activeOpportunityId = explicitOpp.id;
if (!districtId) districtId = explicitOpp.districtId;
}
}
// CASE 2: Auto-discover active opportunity for the resolved district
if (!activeOpportunityId && districtId) {
const opportunity = await Opportunity.findOne({ const opportunity = await Opportunity.findOne({
where: { where: {
districtId, districtId,
@ -131,11 +158,14 @@ export const submitApplication = async (req: AuthRequest, res: Response) => {
} }
// Send Email (Async) // Send Email (Async)
const displayApplicantName = toTitleCase(applicantName);
const displayLocation = toTitleCase(city || preferredLocation);
if (isOpportunityAvailable) { if (isOpportunityAvailable) {
sendOpportunityEmail(email, applicantName, city || preferredLocation, applicationId) sendOpportunityEmail(email, displayApplicantName, displayLocation, applicationId)
.catch(err => console.error('Error sending opportunity email', err)); .catch(err => console.error('Error sending opportunity email', err));
} else { } else {
sendNonOpportunityEmail(email, applicantName, city || preferredLocation) sendNonOpportunityEmail(email, displayApplicantName, displayLocation)
.catch(err => console.error('Error sending non-opportunity email', err)); .catch(err => console.error('Error sending non-opportunity email', err));
} }