Skip to content
Snippets Groups Projects
Fragment.js 1.08 KiB
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 = {
      userId: user.id,
      firstName: user.firstName || '',
      lastName: user.lastName || '',
      email: user.email,
      title: user.title || '',
      affiliation: user.affiliation || '',
      isSubmitting,
      isCorresponding,
    }
    fragment.authors.push(author)
    await fragment.save()
  }