Adding GetClones method
This commit is contained in:
1 parent
939183c0d9
commit
767e910187
6 files changed
+93
-3
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
GraphQLList,
|
||||
GraphQLID
|
||||
} from 'graphql'
|
||||
|
||||
import {
|
||||
OperationsError
|
||||
} from '../../errors'
|
||||
|
||||
import { GetClonesInputType } from '../types/input';
|
||||
import { GetClonesType } from '../types'
|
||||
import { Clone } from '../../models'
|
||||
import logger from '../../config/logger'
|
||||
|
||||
import { isDefined } from '../../config/utils'
|
||||
|
||||
const args = {
|
||||
cloneIdList: {type: GetClonesInputType}
|
||||
}
|
||||
|
||||
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]
|
||||
})
|
||||
|
||||
if(isDefined(existingClone)){
|
||||
clones.push({
|
||||
id: cloneIdList.cloneIdList[i],
|
||||
teamId: existingClone.teamId,
|
||||
botId: existingClone.botId
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return clones
|
||||
} catch (err){
|
||||
logger.error('Get Clones error: %s', err.stack)
|
||||
throw new OperationsError('There has been an error getting the clones.')
|
||||
}
|
||||
}
|
||||
|
||||
const query = {
|
||||
getClones: {
|
||||
type: new GraphQLList(GetClonesType),
|
||||
args,
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
@@ -4,12 +4,14 @@ import {
|
||||
|
||||
import ListClones from './ListClones'
|
||||
import HistoryClones from './HistoryClones'
|
||||
import GetClones from './GetClones'
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: Object.assign(
|
||||
ListClones,
|
||||
HistoryClones
|
||||
HistoryClones,
|
||||
GetClones
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLID
|
||||
} from 'graphql'
|
||||
|
||||
const GetClonesType = new GraphQLObjectType({
|
||||
name: 'GetClones',
|
||||
fields: () => ({
|
||||
id: {type: GraphQLID},
|
||||
teamId: {type: GraphQLID},
|
||||
botId: {type: GraphQLID}
|
||||
})
|
||||
})
|
||||
export default GetClonesType
|
||||
@@ -1,5 +1,7 @@
|
||||
import CloneType from './CloneType'
|
||||
import GetClonesType from './GetClonesType'
|
||||
|
||||
export {
|
||||
CloneType
|
||||
CloneType,
|
||||
GetClonesType
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
@@ -1,5 +1,7 @@
|
||||
import CloneInputType from './Clone'
|
||||
import GetClonesInputType from './GetClones'
|
||||
|
||||
export {
|
||||
CloneInputType
|
||||
CloneInputType,
|
||||
GetClonesInputType
|
||||
};
|
||||
Reference in new issue
Block a user