Skip to content
Snippets Groups Projects
Commit 0aa837e0 authored by Audrey Hamelers's avatar Audrey Hamelers
Browse files

#239 duplicate checking improvement

parent 51b21650
No related branches found
No related tags found
2 merge requests!83Shared data model,!86Dev
......@@ -13,12 +13,10 @@ const SubmitWithHeader = SubmissionHeader(SubmitWithMutations)
const DupeCheckSubmitPage = ({ manuscript, ...props }) => {
const { id, meta } = manuscript
const pmid =
meta.articleIds && meta.articleIds.find(id => id.pubIdType === 'pmid')
? meta.articleIds.find(id => id.pubIdType === 'pmid').id
: null
const { title, articleIds: aids } = meta
const articleIds = aids.map(aid => aid.id)
return (
<Query query={CHECK_DUPES} variables={{ id, pmid, title: meta.title }}>
<Query query={CHECK_DUPES} variables={{ id, articleIds, title }}>
{({ data, loading }) => {
if (loading || !data) {
return (
......
......@@ -40,8 +40,8 @@ export const CREATE_MANUSCRIPT = gql`
`
export const CHECK_DUPES = gql`
query($id: ID!, $pmid: String, $title: String!) {
checkDuplicates(id: $id, pmid: $pmid, title: $title) {
query($id: ID!, $articleIds: [String], $title: String!) {
checkDuplicates(id: $id, articleIds: $articleIds, title: $title) {
...ManuscriptFragment
}
}
......
......@@ -394,7 +394,6 @@ class Manuscript extends EpmcBaseModel {
]),
)
.orderBy('manuscript.updated', 'desc')
.debug()
return manuscripts
}
......
......@@ -90,13 +90,18 @@ const Manuscript = {
}
},
checkDuplicates: async (id, pmid, title, user) => {
checkDuplicates: async (id, articleIds, title, user) => {
let manuscripts = []
if (pmid) {
const idMatches = await ManuscriptAccess.searchArticleIds(pmid, user)
if (articleIds.length > 0) {
const idMatches = []
const matchLists = articleIds.map(aid =>
ManuscriptAccess.searchArticleIds(aid, user),
)
await Promise.all(matchLists)
matchLists.forEach(list => idMatches.concat(list))
manuscripts = manuscripts.concat(
idMatches.reduce((other, each) => {
if (each.id !== id) {
if (each.id !== id && !manuscripts.some(m => m.id === each.id)) {
other.push(each)
}
return other
......
......@@ -19,11 +19,11 @@ const resolvers = {
return ManuscriptManager.all(user)
},
async checkDuplicates(_, { id, pmid, title }, { user }) {
async checkDuplicates(_, { id, articleIds, title }, { user }) {
if (!user) {
throw new Error('You are not authenticated!')
}
return ManuscriptManager.checkDuplicates(id, pmid, title, user)
return ManuscriptManager.checkDuplicates(id, articleIds, title, user)
},
async countByStatus(_, vars, { user }) {
if (!user) {
......
......@@ -23,7 +23,7 @@ extend type Query {
manuscripts: [Manuscript]!
adminManuscripts(external: Boolean): [Manuscript]!
countByStatus: [Count]!
checkDuplicates(id: ID!, pmid: String, title: String!): [Manuscript]
checkDuplicates(id: ID!, articleIds: [String], title: String!): [Manuscript]
searchArticleIds(id: String!): ManuscriptResult!
findByStatus(query: String!, page: Int, pageSize: Int): ManuscriptSearchResult!
searchManuscripts(query: String!, page: Int, pageSize: Int): ManuscriptSearchResult!
......
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