progress track isue for interview level 1 fixed

This commit is contained in:
laxmanhalaki 2026-04-28 08:32:28 +05:30
parent a9018ab0ff
commit b6938abc7c

View File

@ -154,7 +154,7 @@ export const syncApplicationProgress = async (applicationId: string, overallStat
// Statuses that imply the CURRENT stage (single or both parallel) is finished // Statuses that imply the CURRENT stage (single or both parallel) is finished
const completionStatuses = [ const completionStatuses = [
'Submitted', 'Questionnaire Completed', 'Shortlisted', 'Level 1 Approved', 'Submitted', 'Questionnaire Completed', 'Shortlisted', 'Level 1 Approved',
'Level 2 Approved', 'Level 3 Approved', 'Level 2 Approved', 'Level 2 Recommended', 'Level 3 Approved',
'EOR Complete', 'Inauguration', 'Approved', 'Onboarded' 'EOR Complete', 'Inauguration', 'Approved', 'Onboarded'
]; ];
@ -164,7 +164,7 @@ export const syncApplicationProgress = async (applicationId: string, overallStat
const application = await db.Application.findByPk(applicationId); const application = await db.Application.findByPk(applicationId);
// Robust Sync: Prepare ALL stages for batch processing // Robust Sync: Prepare ALL stages for batch processing
const upsertData = []; const upsertData: any[] = [];
for (const stage of ONBOARDING_STAGES) { for (const stage of ONBOARDING_STAGES) {
let status: 'pending' | 'active' | 'completed' = 'pending'; let status: 'pending' | 'active' | 'completed' = 'pending';
let percentage = 0; let percentage = 0;
@ -199,10 +199,36 @@ export const syncApplicationProgress = async (applicationId: string, overallStat
}); });
} }
// Use bulkCreate with updateOnDuplicate to perform an efficient batch upsert // DB Duplication Prevention without Schema Changes (Healing corrupted data loops)
await ApplicationProgress.bulkCreate(upsertData, { const existingRecords = await ApplicationProgress.findAll({ where: { applicationId } });
updateOnDuplicate: ['status', 'completionPercentage', 'stageStartedAt', 'stageCompletedAt'] const seenStages = new Set<string>();
// Purge any ghost duplicates created by old logic
for (const record of existingRecords) {
if (seenStages.has(record.stageName)) {
await record.destroy();
} else {
seenStages.add(record.stageName);
}
}
// Perform single row updates/inserts to enforce exact 1:1 mapping safely
const cleanedRecords = await ApplicationProgress.findAll({ where: { applicationId } });
for (const data of upsertData) {
const existing = cleanedRecords.find((r: any) => r.stageName === data.stageName);
if (existing) {
await existing.update({
stageOrder: data.stageOrder,
status: data.status,
completionPercentage: data.completionPercentage,
stageStartedAt: data.stageStartedAt || existing.stageStartedAt,
stageCompletedAt: data.stageCompletedAt || existing.stageCompletedAt
}); });
} else {
await ApplicationProgress.create(data);
}
}
} }
} }
}; };