UNPKG

jambda

Version:

Easy serverless rest api deploy! Jambda makes it easy to deploy database connected rest api's by providing the least amount of configuration.

32 lines (27 loc) 680 B
import { success } from '../helper/response' import { notFound } from 'boom' import * as repository from '../lib/repository' /** * Get one of the records * If an id is present in the url it returns that entry * If there is no id it returns all the entries * * @param {Schema} model The current model * @returns {Function} An express-middleware */ const __get = model => { const get = repository.get(model) return (req, res, next) => { const { params } = req get(params.id) .then(response => { if (!response) { next(notFound('Record not found!'), res) } else { success(200, response, res) } }) .catch(next) } } export default __get