Skip to content

Commit

Permalink
jac-uk/admin#2663 PSDQ. Calculate stats
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensearle committed Jan 14, 2025
1 parent b17b6d8 commit 3cba5dc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions functions/actions/tasks/updateTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,16 +861,22 @@ export default (config, firebase, db) => {
data: {},
};

const outcomeStats = {};
const passStatus = getApplicationPassStatus(exercise, task);
const failStatus = getApplicationFailStatus(exercise, task);
outcomeStats[passStatus] = 0;
outcomeStats[failStatus] = 0;
// get candidateForm
const candidateForm = await getDocument(db.collection('candidateForms').doc(task.formId));
if (!candidateForm) { result.message = 'No candidate form'; return result; }

// TODO update application status here, perhaps, or just get stats for completed vs not completed
// get responses
const responses = await getDocuments(db.collection('candidateForms').doc(task.formId).collection('responses'));
if (!responses.length) { result.message = 'No responses'; return result; }

// populate stats
const stats = {};
stats.completed = 0;
stats.notCompleted = 0;
responses.forEach(response => response.status === 'completed' ? stats.completed++: stats.notCompleted++ );

result.success = true;
result.data['_stats.totalForEachOutcome'] = outcomeStats;
result.data._stats = { ...task._stats, ...stats };

return result;
}
Expand Down

0 comments on commit 3cba5dc

Please sign in to comment.