From c41692745cf3e25b39775e4c096a4a14d6adc069 Mon Sep 17 00:00:00 2001 From: Matthew Crouch Date: Tue, 24 Oct 2023 09:16:24 -0400 Subject: [PATCH] MMT-3409: Refactor code --- src/cmr/concepts/collectionDraftProposal.js | 5 ++--- src/cmr/concepts/concept.js | 22 +++++++++------------ src/cmr/concepts/draft.js | 10 +++++----- src/cmr/concepts/draftConcept.js | 5 ++--- src/types/tool.graphql | 4 ++-- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/cmr/concepts/collectionDraftProposal.js b/src/cmr/concepts/collectionDraftProposal.js index 6800c2c1d..4234ded5e 100644 --- a/src/cmr/concepts/collectionDraftProposal.js +++ b/src/cmr/concepts/collectionDraftProposal.js @@ -92,8 +92,7 @@ export default class CollectionDraftProposal extends Concept { } fetch(searchParams) { - // eslint-disable-next-line no-param-reassign - searchParams = mergeParams(searchParams) + const params = mergeParams(searchParams) // Default an array to hold the promises we need to make depending on the requested fields const promises = [] @@ -106,7 +105,7 @@ export default class CollectionDraftProposal extends Concept { // Construct the promise that will request data from the umm endpoint promises.push( - this.fetchUmm(searchParams, ummKeys, ummHeaders) + this.fetchUmm(params, ummKeys, ummHeaders) ) this.response = Promise.all(promises) diff --git a/src/cmr/concepts/concept.js b/src/cmr/concepts/concept.js index fa3973a83..91ccbe80e 100644 --- a/src/cmr/concepts/concept.js +++ b/src/cmr/concepts/concept.js @@ -362,15 +362,14 @@ export default class Concept { * @param {Object} providedHeaders Headers requested by the query */ ingest(data, requestedKeys, providedHeaders) { - // eslint-disable-next-line no-param-reassign - data = mergeParams(data) + const params = mergeParams(data) this.logKeyRequest(requestedKeys, 'ingest') // Construct the promise that will ingest data into CMR this.response = cmrIngest( this.getConceptType(), - data, + params, providedHeaders, this.ingestPath ) @@ -383,15 +382,14 @@ export default class Concept { * @param {Object} providedHeaders Headers requested by the query */ delete(data, requestedKeys, providedHeaders) { - // eslint-disable-next-line no-param-reassign - data = mergeParams(data) + const params = mergeParams(data) this.logKeyRequest(requestedKeys, 'ingest') // Construct the promise that will delete data from CMR this.response = cmrDelete( this.getConceptType(), - data, + params, providedHeaders, this.ingestPath ) @@ -455,8 +453,7 @@ export default class Concept { * @param {Object} searchParams Parameters provided by the query */ fetch(searchParams) { - // eslint-disable-next-line no-param-reassign - searchParams = mergeParams(searchParams) + const params = mergeParams(searchParams) // Default an array to hold the promises we need to make depending on the requested fields const promises = [] @@ -469,11 +466,10 @@ export default class Concept { const { cursor - } = searchParams + } = params if (cursor) { - // eslint-disable-next-line no-param-reassign - delete searchParams.cursor + delete params.cursor } const { @@ -493,7 +489,7 @@ export default class Concept { } promises.push( - this.fetchJson(this.arrayifyParams(searchParams), jsonKeys, jsonHeaders) + this.fetchJson(this.arrayifyParams(params), jsonKeys, jsonHeaders) ) } else { // Push a null promise to the array so that the umm promise always exists as @@ -516,7 +512,7 @@ export default class Concept { // Construct the promise that will request data from the umm endpoint promises.push( - this.fetchUmm(this.arrayifyParams(searchParams), ummKeys, ummHeaders) + this.fetchUmm(this.arrayifyParams(params), ummKeys, ummHeaders) ) } else { promises.push( diff --git a/src/cmr/concepts/draft.js b/src/cmr/concepts/draft.js index b34ba3d49..afc01994d 100644 --- a/src/cmr/concepts/draft.js +++ b/src/cmr/concepts/draft.js @@ -1,10 +1,11 @@ import { pick, uniq } from 'lodash' import { pickIgnoringCase } from '../../utils/pickIgnoringCase' -import Concept from './concept' import { mergeParams } from '../../utils/mergeParams' import { cmrIngest } from '../../utils/cmrIngest' +import Concept from './concept' + export default class Draft extends Concept { /** * Instantiates a Draft object @@ -16,7 +17,7 @@ export default class Draft extends Concept { super(conceptType, headers, requestInfo, params) const { - draftConceptId = '', + draftConceptId, providerId } = params @@ -196,8 +197,7 @@ export default class Draft extends Concept { publish(data, requestedKeys, providedHeaders) { const { ummVersion } = data - // eslint-disable-next-line no-param-reassign - data = mergeParams(data) + const params = mergeParams(data) // Default headers const defaultHeaders = { @@ -222,7 +222,7 @@ export default class Draft extends Concept { // Construct the promise that will ingest data into CMR this.response = cmrIngest( this.getConceptType(), - pick(data, this.getPermittedPublishKeys()), + pick(params, this.getPermittedPublishKeys()), permittedHeaders, this.publishPath ) diff --git a/src/cmr/concepts/draftConcept.js b/src/cmr/concepts/draftConcept.js index 21de9c593..cebb34a7f 100644 --- a/src/cmr/concepts/draftConcept.js +++ b/src/cmr/concepts/draftConcept.js @@ -95,8 +95,7 @@ export default class DraftConcept extends Concept { } fetch(searchParams) { - // eslint-disable-next-line no-param-reassign - searchParams = mergeParams(searchParams) + const params = mergeParams(searchParams) // Default an array to hold the promises we need to make depending on the requested fields const promises = [] @@ -109,7 +108,7 @@ export default class DraftConcept extends Concept { // Construct the promise that will request data from the umm endpoint promises.push( - this.fetchUmm(searchParams, ummKeys, ummHeaders) + this.fetchUmm(params, ummKeys, ummHeaders) ) this.response = Promise.all(promises) diff --git a/src/types/tool.graphql b/src/types/tool.graphql index a4bfba95f..1d56b8fec 100644 --- a/src/types/tool.graphql +++ b/src/types/tool.graphql @@ -128,7 +128,7 @@ type Mutation { type ToolMutationResponse { "The unique concept id assigned to the tool." - conceptId: String + conceptId: String! "The revision of the tool." - revisionId: String + revisionId: String! }