Skip to content

Instantly share code, notes, and snippets.

@pchw
Created October 24, 2016 01:54
Show Gist options
  • Save pchw/9c13a5d62da0a499f111a4f48fd1b579 to your computer and use it in GitHub Desktop.
Save pchw/9c13a5d62da0a499f111a4f48fd1b579 to your computer and use it in GitHub Desktop.
reversible state converter
module.exports =
converter: (targetObjs, beforeObj, afterObj, isCheckBefore, isReverse, callback)->
if isReverse
if isCheckBefore
conditions = _.merge {}, afterObj
updates = _.merge {}, beforeObj
else
if isCheckBefore
conditions = _.merge {}, beforeObj
updates = _.merge {}, afterObj
conditions[$isolated] = true
conditions._id =
$in: _.map targetObjs, '_id'
Documnt.update conditions, updates,
$multi: true
, callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment