Created
August 14, 2018 00:49
-
-
Save marianoqueirel/34508ecd8774f380423807a47a6ce662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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