Skip to content

Instantly share code, notes, and snippets.

@marianoqueirel
Created August 9, 2018 20:18
Show Gist options
  • Save marianoqueirel/5ae20f37644db17ddb5009e2c72c0823 to your computer and use it in GitHub Desktop.
Save marianoqueirel/5ae20f37644db17ddb5009e2c72c0823 to your computer and use it in GitHub Desktop.
export function getPendingStudents(req, res) {
Student.find({state: {$in: ['Visitante', 'EntrevistaDirectorFinalizada', 'Interesado', 'Entrevista2', 'ListoParaIngresar']}})
.then(_students => {
let students = JSON.parse(JSON.stringify(_students));
students = students.filter(student => {
switch (student.state) {
case 'Visitante':
return true;
break;
case 'EntrevistaDirectorFinalizada':
return true;
break;
case 'Interesado':
return true;
break;
case 'Entrevista2':
let history;
for(let _history of student.history) {
if(_history.state === 'Entrevista2') history = JSON.parse(JSON.stringify(_history));
}
if (history.extra != null && history.extra.turn != null && history.extra.scheduled) {
if (history.extra.turn.day != null) {
return moment(history.extra.turn.day).isBefore(moment());
}
}
return history.extra == null || !history.extra.scheduled;
break;
case 'ListoParaIngresar':
return true;
break;
}
});
return students;
})
.then(respondWithResult(res))
.catch(handleError(res));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment