Last active
August 29, 2015 14:04
-
-
Save artyomtrityak/6037578ba4c31f1d68d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var skills = data.skills, | |
activities = data.activities, | |
works = data.works, | |
schools = data.schools; | |
delete data.schools; | |
delete data.works; | |
delete data.activities; | |
delete data.skills; | |
function PartStoring(RESUME, PartObj, parts, name) { | |
var promises = []; | |
parts.forEach(function(part) { | |
delete part._id; | |
var promise = PartObj.create(part, function(err, result) { | |
if (err) { | |
throw err; | |
} | |
RESUME[name].push(result); | |
}); | |
promises.push(promise); | |
}); | |
return Q.all(promises); | |
} | |
Resume | |
.create(data, function(err, resume) { | |
RESUME = resume; | |
if (err) { | |
res.send(400, err); | |
} | |
}) | |
.then(function() { | |
return PartStoring(RESUME, Skill, skills, 'skills'); | |
}) | |
.then(function() { | |
return PartStoring(RESUME, Activity, activities, 'activities'); | |
}) | |
.then(function() { | |
return PartStoring(RESUME, Work, works, 'works'); | |
}) | |
.then(function() { | |
return PartStoring(RESUME, School, schools, 'schools'); | |
}).then(function() { | |
return RESUME.save(); | |
}).then(function() { | |
RESUME.populate('skills schools activities works', function(err, result) { | |
res.send(200, result); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can be changed to