Newer
Older
class Fragment {
constructor({ fragment }) {
this.fragment = fragment
}
async getFragmentData({ handlingEditor = {} }) {
const { fragment: { metadata, recommendations = [], id } } = this
const heRecommendation = recommendations.find(
rec => rec.userId === handlingEditor.id,
)
let { title, abstract } = metadata
const { type } = metadata
title = title.replace(/<(.|\n)*?>/g, '')
abstract = abstract ? abstract.replace(/<(.|\n)*?>/g, '') : ''
return {
id,
type,
title,
abstract,
recommendations,
heRecommendation,
}
}
async addAuthor({ user, isSubmitting, isCorresponding }) {
const { fragment } = this
fragment.authors = fragment.authors || []
const author = {
firstName: user.firstName || '',
lastName: user.lastName || '',
email: user.email,
title: user.title || '',
affiliation: user.affiliation || '',
isSubmitting,
isCorresponding,
}
fragment.authors.push(author)
await fragment.save()
Sebastian Mihalache
committed
async getAuthorData({ UserModel }) {
const { fragment: { authors } } = this
const submittingAuthorData = authors.find(
author => author.isSubmitting === true,
)

Alexandru Munteanu
committed
const submittingAuthor = await UserModel.find(submittingAuthorData.id)
Sebastian Mihalache
committed
const authorsPromises = authors.map(async author => {

Alexandru Munteanu
committed
const user = await UserModel.find(author.id)
Sebastian Mihalache
committed
return `${user.firstName} ${user.lastName}`
})
const authorsList = await Promise.all(authorsPromises)
return {
authorsList,
submittingAuthor,
}
}
getReviewerInvitations({ agree = true }) {
const { fragment: { invitations = [] } } = this
Sebastian Mihalache
committed
return agree
? invitations.filter(
inv =>
inv.role === 'reviewer' &&
inv.hasAnswer === true &&
inv.isAccepted === true,
)
: invitations.filter(
inv => inv.role === 'reviewer' && inv.hasAnswer === false,
)
}
}
module.exports = Fragment