Skip to content

Instantly share code, notes, and snippets.

@marianoqueirel
Created August 14, 2018 00:49
Show Gist options
  • Save marianoqueirel/34508ecd8774f380423807a47a6ce662 to your computer and use it in GitHub Desktop.
Save marianoqueirel/34508ecd8774f380423807a47a6ce662 to your computer and use it in GitHub Desktop.
export function importStudents(req, res) {
for (let student of STUDENTS) {
const ids = [];
let grade = {
year: '2019',
level: student.level,
name: student.gradeName,
turn: student.gradeTurn
}
Year.findOne(grade)
.where('section')
.eq(null)
.exec()
.then(year => {
ids.push(year._id);
Reflect.deleteProperty(grade, 'turn');
return Year.findOne(grade)
.where('sections')
.eq(null)
.where('turn')
.eq(null)
.exec()
})
.then(year => {
ids.unshift(year._id);
student.name = student.name;
student.sections = ids;
student.state = 'Visitante';
student.contact = student.contact;
student.history = {
state: 'Visitante',
user: req.params.id,
date: new Date(),
comment: 'Imported'
}
Student.create(student)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment