Newer
Older
li-add-unpaywall / index.js
@mbouri mbouri on 20 Dec 2021 803 bytes test: update unit test
'use strict';
const got = require('got');
const config = require('./config/config');
const _ = require('lodash');

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 }) => {
    // TODO: check enrichments format:
    const enrichments = body[0].value;
    _.set(docObject, 'enrichments.openAccess.unpaywall', enrichments);
    return cb();
  }).catch(error => {
    docObject.errCode = error.name;
    docObject._errMsg = error.message;
    error.nonBlocking = true;
    return cb(error);
  });
};

module.exports = business;