Skip to content
Snippets Groups Projects
Commit dd47e235 authored by Bogdan Cochior's avatar Bogdan Cochior
Browse files

refactor(owners): refactor adding owners to fragment

parent be919b62
No related branches found
No related tags found
1 merge request!13Sprint #14
const get = require('lodash/get') const get = require('lodash/get')
const setFragmentOwners = (fragment = {}, author = {}) => {
const { owners = [] } = fragment
if (author.isSubmitting) {
const authorAlreadyOwner = owners.includes(author.id)
if (!authorAlreadyOwner) {
return [author.id, ...owners]
}
}
return owners
}
class Fragment { class Fragment {
constructor({ fragment }) { constructor({ fragment }) {
this.fragment = fragment this.fragment = fragment
...@@ -20,6 +9,17 @@ class Fragment { ...@@ -20,6 +9,17 @@ class Fragment {
this.fragment = newFragment this.fragment = newFragment
} }
static setFragmentOwners(fragment = {}, author = {}) {
const { owners = [] } = fragment
if (author.isSubmitting) {
const authorAlreadyOwner = owners.includes(author.id)
if (!authorAlreadyOwner) {
return [author.id, ...owners]
}
}
return owners
}
async getFragmentData({ handlingEditor = {} }) { async getFragmentData({ handlingEditor = {} }) {
const { fragment: { metadata = {}, recommendations = [], id } } = this const { fragment: { metadata = {}, recommendations = [], id } } = this
const heRecommendation = recommendations.find( const heRecommendation = recommendations.find(
...@@ -54,7 +54,7 @@ class Fragment { ...@@ -54,7 +54,7 @@ class Fragment {
isCorresponding, isCorresponding,
} }
fragment.authors.push(author) fragment.authors.push(author)
fragment.owners = setFragmentOwners(fragment, author) fragment.owners = this.constructor.setFragmentOwners(fragment, author)
await fragment.save() await fragment.save()
return author return author
......
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