'use strict'; const got = require('got'); const config = require('./config/config'); const _ = require('lodash'); const handleError = require('./error-handler'); const business = {}; business.doTheJob = function (docObject, cb) { const doi = docObject.doi; // if no DOI found if (doi === undefined || doi === '') { return cb(); } const unpaywallWsUrl = config.unpaywallWsUrl; got.post(unpaywallWsUrl, { json: { value: doi }, responseType: 'json' }).then(({ body }) => { const enrichments = body[0].value; _.set(docObject, 'enrichments.openAccess.unpaywall', enrichments); return cb(); }).catch(error => { return cb(handleError(docObject, error.name)); }); }; module.exports = business;