Created
March 4, 2017 04:41
-
-
Save suissa/c4bcfa3328ed7a5d52f609bf175dcc61 to your computer and use it in GitHub Desktop.
FInd by ID no Mongoose funcional
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
const getQuery = ( req ) => ( { _id: req.params.id } ) | |
const getFields = ( req ) => | |
( req.query.fields ) | |
? req.query.fields.replace( ',', ' ' ) | |
: '' | |
const getCbSuccess = ( res ) => require( './ribossomos/success-200-json' )( res ) | |
const getCbError = ( res ) => require( './ribossomos/error-json' )( res ) | |
module.exports = ( Organism ) => | |
( req, res ) => Organism.findOne( getQuery( req ), getFields( req ) ) | |
.exec() | |
.then( getCbSuccess( res ) ) | |
.catch( getCbError( res ) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Massa, estava precisando dessa query.. :)