Making the clones filterable by botType (optional)

This commit is contained in:
Unknown committed 2019-03-23 15:56:01 +01:00
1 parent 8656d25616
commit b4a2950e48
2 files changed
+22 -9

No files matched your search

+11 -5
View File
@@ -1,4 +1,4 @@
import { GraphQLList } from 'graphql'
import { GraphQLList, GraphQLString } from 'graphql'
import { AuthentificationError, OperationsError } from '../../errors'
import { CloneType } from '../types'
import { Clone } from '../../models'
@@ -6,9 +6,11 @@ import logger from '../../config/logger'
import cloneDetails from '../cloneDetails'
import teamQuery from '../../graphQLCalls/teamQuery'
const args = {}
const args = {
botType: { type: GraphQLString }
}
const resolve = async(parent, args, context) => {
const resolve = async(parent, { botType }, context) => {
logger.debug('Retrieving History Clones.')
try {
if (!context.userId) {
@@ -25,8 +27,12 @@ const resolve = async(parent, args, context) => {
clones[i] = await cloneDetails(context.userId, team.data.data.teams_TeamById, clones[i])
clones[i].botType = clones[i].kind // Only for listing we show the teams value
}
return clones
if (botType) {
var filtered = clones.filter((value) => value.botType === botType)
return filtered
} else {
return clones
}
} catch (err) {
logger.error('Retrieving History Clones error: %s', err.stack)
throw new OperationsError('There has been an error retrieving history clones.')
+11 -4
View File
@@ -1,4 +1,4 @@
import { GraphQLList } from 'graphql'
import { GraphQLList, GraphQLString } from 'graphql'
import { AuthentificationError, OperationsError } from '../../errors'
import { CloneType } from '../types'
import { Clone } from '../../models'
@@ -8,9 +8,11 @@ import getCloneLogs from '../../kubernetes/getClonePodLogs'
import cloneDetails from '../cloneDetails'
import teamQuery from '../../graphQLCalls/teamQuery'
const args = {}
const args = {
botType: { type: GraphQLString }
}
const resolve = async(parent, args, context) => {
const resolve = async (parent, { botType }, context) => {
logger.debug('List Clones -> Entering Fuction.')
try {
if (!context.userId) {
@@ -32,7 +34,12 @@ const resolve = async(parent, args, context) => {
clones[i].botType = clones[i].kind // Only for listing we show the teams value
clones[i].botSlug = clones[i].botSlug
}
return clones
if (botType) {
var filtered = clones.filter((value) => value.botType === botType)
return filtered
} else {
return clones
}
} catch (err) {
logger.error('List Clones error: %s', err.stack)
throw new OperationsError('There has been an error listing the clones.')