valoracionSearch.js
899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const createError = require('http-errors')
const su = require('superagent')
const {
isEmpty, isNil, contains, path,
head, identity, ifElse, empty, 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)))
}