Skip to content

Instantly share code, notes, and snippets.

@suissa
Created March 4, 2017 04:41
Show Gist options
  • Save suissa/c4bcfa3328ed7a5d52f609bf175dcc61 to your computer and use it in GitHub Desktop.
Save suissa/c4bcfa3328ed7a5d52f609bf175dcc61 to your computer and use it in GitHub Desktop.
FInd by ID no Mongoose funcional
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 ) )
@higordiego
Copy link

Massa, estava precisando dessa query.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment