Commit e456fbf9 authored by Alf Eaton's avatar Alf Eaton
Browse files

Search both sources

parent 65adad4a
......@@ -4,6 +4,7 @@
"main": "dist",
"author": "Alf Eaton <eaton.alf@gmail.com>",
"license": "MIT",
"files": ["src", "dist", ".babelrc"],
"dependencies": {
"axios": "^0.17.1",
"cors": "^2.8.4",
......
const express = require('express')
const cors = require('cors')
const eutils = require('./pmc')
const pubmed = require('./pubmed')
const pmc = require('./pmc')
const app = express()
app.set('json spaces', 2)
......@@ -16,23 +18,29 @@ app.use('/author', (req, res) => {
}
const authorByPosition = results => {
if (!results.length) throw new Error('No matches')
if (!results.length) return null
const { title, authors } = results[0]
const { source, id, title, authors } = results[0]
if (!authors[position]) throw new Error('Position not found')
const { name, email } = authors[position]
return { title, name, email }
return { source, id, title, author: { name, email } }
}
eutils.search({ term })
.then(eutils.fetch({ retmax: 1 }))
.then(eutils.parse)
.then(authorByPosition)
.then(output => {
res.json(output)
Promise.all([
pubmed.search({ term })
.then(pubmed.fetch({ retmax: 1 }))
.then(pubmed.parse)
.then(authorByPosition),
pmc.search({ term })
.then(pmc.fetch({ retmax: 1 }))
.then(pmc.parse)
.then(authorByPosition)
]).then(output => {
res.json(output.filter(item => item))
})
.catch(e => {
res.json({
......
......@@ -13,6 +13,8 @@ module.exports = {
})
const parseArticle = article => ({
source: 'pmc',
id: article.get('string(front/article-meta/article-id[@pub-id-type="pmc"])'),
title: article.get('string(front/article-meta/title-group/article-title[1])'),
authors: article.find('front/article-meta/contrib-group/contrib').map(parseAuthor)
})
......
......@@ -16,6 +16,8 @@ module.exports = {
})
const parseArticle = article => ({
source: 'pubmed',
id: article.get('string(../PMID)'),
title: article.get('string(ArticleTitle)'),
authors: article.find('AuthorList/Author').map(parseAuthor)
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment