From 0ddd35a460fbbd9ae877340180dbab2b1664696e Mon Sep 17 00:00:00 2001 From: "mati108@gmail.com" <34651529+matbenitez@users.noreply.github.com> Date: Sat, 9 Feb 2019 14:59:10 -0300 Subject: [PATCH] Simplifying input --- server/src/schema/queries/GetClones.js | 32 ++++++++++++++-------- server/src/schema/types/input/GetClones.js | 15 ---------- server/src/schema/types/input/index.js | 4 +-- 3 files changed, 22 insertions(+), 29 deletions(-) delete mode 100644 server/src/schema/types/input/GetClones.js diff --git a/server/src/schema/queries/GetClones.js b/server/src/schema/queries/GetClones.js index 45a43eadf..7125edc7b 100644 --- a/server/src/schema/queries/GetClones.js +++ b/server/src/schema/queries/GetClones.js @@ -7,31 +7,41 @@ import { OperationsError } from '../../errors' -import { GetClonesInputType } from '../types/input'; import { GetClonesType } from '../types' import { Clone } from '../../models' import logger from '../../config/logger' - +import mongoose from 'mongoose' import { isDefined } from '../../config/utils' const args = { - cloneIdList: {type: GetClonesInputType} + cloneIdList: { type: new GraphQLList(GraphQLID) } } const resolve = async(parent, { cloneIdList }, context) => { logger.debug('Get Clones -> Entering Fuction. %j', cloneIdList) try{ let clones = [] - for (var i = 0; i < cloneIdList.cloneIdList.length; i++) { - let existingClone = await Clone.findOne({ - _id: cloneIdList.cloneIdList[i] - }) + for (var i = 0; i < cloneIdList.length; i++) { - if(isDefined(existingClone)){ + if(mongoose.Types.ObjectId.isValid(cloneIdList[i])){ + let existingClone = await Clone.findOne({ + _id: cloneIdList[i] + }) + + if(isDefined(existingClone)){ + clones.push({ + id: cloneIdList[i], + teamId: existingClone.teamId, + botId: existingClone.botId + }) + }else{ + clones.push({ + id: cloneIdList[i] + }) + } + } else { clones.push({ - id: cloneIdList.cloneIdList[i], - teamId: existingClone.teamId, - botId: existingClone.botId + id: cloneIdList[i] }) } diff --git a/server/src/schema/types/input/GetClones.js b/server/src/schema/types/input/GetClones.js deleted file mode 100644 index dcdcd1fad..000000000 --- a/server/src/schema/types/input/GetClones.js +++ /dev/null @@ -1,15 +0,0 @@ -import { - GraphQLInputObjectType, - GraphQLList, - GraphQLID -} from 'graphql'; - -const Type = new GraphQLInputObjectType({ - name: 'GetClonesInput', - description: 'Allows to receive a list of clone ids to get information', - fields: () => ({ - cloneIdList: { type: new GraphQLList(GraphQLID) } - }) -}); - -export default Type; diff --git a/server/src/schema/types/input/index.js b/server/src/schema/types/input/index.js index 6e528aa15..e51b0ca74 100644 --- a/server/src/schema/types/input/index.js +++ b/server/src/schema/types/input/index.js @@ -1,7 +1,5 @@ import CloneInputType from './Clone' -import GetClonesInputType from './GetClones' export { - CloneInputType, - GetClonesInputType + CloneInputType };