Last active
August 29, 2015 14:11
-
-
Save xolubi/c6683dca5a88724eed01 to your computer and use it in GitHub Desktop.
Strip uniques before update (SAILS)
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
stripUniques: function(id, data, cb){ | |
this.findOne({id: id}).exec(function findCB(err, result){ | |
if (err) { | |
//bubble error back to callback | |
return cb(err); | |
} else if (!result) { | |
//id passed is invalid. return empty object and deal with this in callback | |
return cb(null, {}); | |
} else { | |
if (data) { | |
//do this for all uniques in model | |
if (data.name && result.name == data.name) { | |
delete data.name; | |
} | |
return cb(null, data); | |
} else { | |
//data is empty. return empty object | |
return cb(null, {}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment