Commit b77c2046 authored by Audrey Hamelers's avatar Audrey Hamelers
Browse files

#1233

parent 761cb01e
......@@ -59,6 +59,7 @@ async function grantLinkCheck() {
}
await linkingManuscripts.reduce(async (promise, m) => {
await promise
delete m.teams
m.fundingState = 'Grants linked'
await m.saveWithTrx(trx)
return Promise.resolve()
......
......@@ -16,14 +16,14 @@ module.exports.createGrantLinks = async function createGrantLinks(
}.${moment().format('YYYY_MM_DD-HH_mm_SS')}.xml`
const sendManuscripts = manuscripts.reduce((list, manuscript) => {
const articleIds =
manuscript['meta,article_ids'] &&
manuscript['meta,article_ids']
manuscript['meta,articleIds'] &&
manuscript['meta,articleIds']
.filter(a => ['pmcid', 'pmid'].includes(a.pubIdType))
.sort((a, b) => (a.pubIdType > b.pubIdType ? 1 : -1))
const fundingGroup =
(manuscript['meta,funding_group'] &&
manuscript['meta,funding_group'].length > 0 &&
manuscript['meta,funding_group']) ||
(manuscript['meta,fundingGroup'] &&
manuscript['meta,fundingGroup'].length > 0 &&
manuscript['meta,fundingGroup']) ||
undefined
if (
articleIds &&
......@@ -118,13 +118,15 @@ function sendXML(contents, filename) {
}
async function emailGrantPis(manuscript, grantList) {
const { teams, id } = manuscript
const releaseDelay = manuscript['meta,release_delay']
const { teams, id, status } = manuscript
const releaseDelay = manuscript['meta,releaseDelay']
const title = manuscript['meta,title']
const fundingGroup = manuscript['meta,funding_group']
const fundingGroup = manuscript['meta,fundingGroup']
const emails = teams.map(t => t.users[0].identities[0].email)
const { teamMembers: rTeam } = teams.find(t => t.role === 'reviewer') || {}
const [reviewer] = rTeam || []
const { users } =
teams.find(t => t.roleName === 'reviewer') ||
teams.find(t => t.roleName === 'submitter')
const [user] = users
if (!fundingGroup || fundingGroup.length === 0) return true
if (fundingGroup.some(g => emails.includes(g.pi.email))) return true
......@@ -149,10 +151,12 @@ async function emailGrantPis(manuscript, grantList) {
id,
title,
releaseDelay,
status,
}
const reviewerName = reviewer && reviewer.alias.name
const { givenNames, surname } = user
const linkName = { givenNames, surname }
await Promise.all(
piList.map(async li => grantEmail(li.pi, li.awards, manInfo, reviewerName)),
piList.map(async li => grantEmail(li.pi, li.awards, manInfo, linkName)),
)
return true
}
const grantsAddedTemplate = (pi, grants, manInfo, reviewer) => `
const grantsAddedTemplate = (pi, grants, manInfo, user) => `
<p>Dear ${pi.title ? `${pi.title} ` : ''}${
pi.givenNames ? `${pi.givenNames} ` : ''
}${pi.surname},</p>
<p>This message is to inform you that your grant${
grants.length > 1 ? 's' : ''
}, listed below, ha${
grants.length > 1 ? 've' : 's'
} been linked to a paper deposited with Europe PMC plus:<p>
}, listed below, ha${grants.length > 1 ? 've' : 's'} been linked to a paper ${
manInfo.status === 'link-existing' ? 'via' : 'deposited with'
} Europe PMC plus:<p>
<ul>${grants
.map(g => `<li>${g.fundingSource} ${g.awardId}, <em>${g.title}</em></li>`)
.join('')}</ul>
<p>The linked paper is <em>${manInfo.title}</em> (${
manInfo.id
}), under the review of ${reviewer.givenNames} ${reviewer.surname}.</p>
<p>If you are satisfied that this link has been made correctly, no further action is required. The paper will be uploaded to Europe PMC ${
manInfo.releaseDelay === '0'
? 'immediately'
: `${manInfo.releaseDelay} month${
manInfo.releaseDelay === '1' ? '' : 's'
}`
} after publication.</p>
<p>The linked paper is <em>${manInfo.title}</em> (${manInfo.id}), linked by ${
user.givenNames
} ${user.surname}.</p>
<p>If you are satisfied that this link has been made correctly, no further action is required. ${
manInfo.status === 'link-existing'
? '</p>'
: `The paper will be uploaded to Europe PMC ${
manInfo.releaseDelay === '0'
? 'immediately'
: `${manInfo.releaseDelay} month${
manInfo.releaseDelay === '1' ? '' : 's'
}`
} after publication.</p>`
}
<p>If you have any questions, or think this link has been made in error, please respond to this message for assistance.</p>
<p>Sincerely,</p>
<p>The Europe PMC Helpdesk</p>
......
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