Created
May 13, 2012 23:00
-
-
Save aroman/2690688 to your computer and use it in GitHub Desktop.
Assignment move strategy
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
update_assignment: (token, assignment, cb) -> | |
# Pull the assignment from the current course, | |
# push it onto the new one, save it, | |
# and finally update the assignment fields. | |
Course.update { | |
owner: token.username | |
assignments: assignment._id | |
}, | |
{ | |
$pull: {assignments: assignment._id} | |
}, | |
{}, | |
(err, num_affected) => | |
Course | |
.findOne({'owner': token.username, '_id': assignment.course}) | |
.run (err, course) => | |
course.assignments.push assignment._id | |
course.save (err) => | |
Assignment.update { | |
owner: token.username | |
_id: assignment._id | |
}, | |
{ | |
title: assignment.title | |
date: assignment.date | |
details: assignment.details | |
done: assignment.done | |
archived: assignment.archived | |
}, | |
{}, | |
cb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment