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
const completionStatuses = [
'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'
];
@ -164,7 +164,7 @@ export const syncApplicationProgress = async (applicationId: string, overallStat
const application = await db.Application.findByPk(applicationId);
// Robust Sync: Prepare ALL stages for batch processing
const upsertData = [];
const upsertData: any[] = [];
for (const stage of ONBOARDING_STAGES) {
let status: 'pending' | 'active' | 'completed' = 'pending';
let percentage = 0;
@ -199,10 +199,36 @@ export const syncApplicationProgress = async (applicationId: string, overallStat
});
}
// Use bulkCreate with updateOnDuplicate to perform an efficient batch upsert
await ApplicationProgress.bulkCreate(upsertData, {
updateOnDuplicate: ['status', 'completionPercentage', 'stageStartedAt', 'stageCompletedAt']
// DB Duplication Prevention without Schema Changes (Healing corrupted data loops)
const existingRecords = await ApplicationProgress.findAll({ where: { applicationId } });
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);
}
}
}
}
};