Skip to content

Instantly share code, notes, and snippets.

@aroman
Created May 13, 2012 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroman/2690688 to your computer and use it in GitHub Desktop.
Save aroman/2690688 to your computer and use it in GitHub Desktop.
Assignment move strategy
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