valoracionSearch.js
901 Bytes
const createError = require('http-errors')
const su = require('superagent')
const {
isNil, path, head, ifElse, always, prop,
} = require('ramda')
const dbhost = process.env.COUCHDB_URL
const dbname = process.env.DB_VALORACIONES
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
const findValoracion = (payload) =>
su.post(`${dbhost}/${dbname}/_find`)
.set(headers)
.send(JSON.stringify(payload))
.then(path(['body', 'docs']))
.then(head)
.then(ifElse(isNil, always(null), prop('valoracion')))
module.exports = (req, res, next) => {
const { id, mail } = req.params
const params = {
selector: {
id: `${id}`,
usuario: { mail }
}
}
findValoracion(params)
.then((valoracion) => res.json({ valoracion, success: true, error: false }))
.catch(error => next(createError(500, error, { expose: true })))
}