Add and remove bot to ecosystem

This commit is contained in:
Matias committed 2019-07-03 20:10:19 -03:00
1 parent 6d28784d91
commit 9a6b8a1572
9 files changed
+227 -4

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
import logger from '../../utils/logger'
import { BotInputType, } from '../types/input'
import { BotType, } from '../types'
import { Ecosystem } from '../../models'
export const args = { bot: { type: BotInputType } }
const resolve = async (parent, { bot }, context) => {
logger.debug('addBot -> Dev team: %s. Bot: %s', bot.devTeam, bot.codeName)
try {
let userEcosystem = await Ecosystem.findOne({
authId: context.userId
})
if (!userEcosystem) {
throw 'Ecosystem not found for the user.'
}
let newBotClone
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
const auxTeam = userEcosystem.devTeams[i]
if (auxTeam.codeName === bot.devTeam) {
for (let j = 0; j < auxTeam.bots.length; j++) {
const auxBot = auxTeam.bots[j]
if (auxBot.codeName === bot.codeName) {
for (let k = 0; k < auxBot.products.length; k++) {
const auxProduct = auxBot.products[k]
if (auxProduct.codeName === bot.productCodeName) {
newBotClone = {
displayName: auxBot.displayName,
codeName: auxBot.codeName + '-' + bot.cloneId,
type: auxBot.type,
profilePicture: auxBot.profilePicture,
cloneId: bot.cloneId,
products: [auxProduct]
}
auxTeam.bots.push(newBotClone)
break
}
}
break
}
}
break
}
}
if (newBotClone) {
await userEcosystem.save()
return newBotClone
} else {
throw 'Algobot not found.'
}
} catch (err) {
logger.error('addBot -> Error: %s', err.message)
throw err
}
}
const mutation = {
addBot: {
type: BotType,
args,
resolve,
}
}
export default mutation;
+63
View File
@@ -0,0 +1,63 @@
import logger from '../../utils/logger'
import { BotInputType, } from '../types/input'
import { BotType, } from '../types'
import { Ecosystem } from '../../models'
export const args = { bot: { type: BotInputType } }
const resolve = async (parent, { bot }, context) => {
logger.debug('removeBot -> Dev team: %s. Bot: %s', bot.devTeam, bot.codeName)
try {
let userEcosystem = await Ecosystem.findOne({
authId: context.userId
})
if (!userEcosystem) {
throw 'Ecosystem not found for the user.'
}
let removedBotClone
for (let i = 0; i < userEcosystem.devTeams.length; i++) {
const auxTeam = userEcosystem.devTeams[i]
if (auxTeam.codeName === bot.devTeam) {
for (let j = 0; j < auxTeam.bots.length; j++) {
const auxBot = auxTeam.bots[j]
if (auxBot.codeName + '-' + bot.cloneId === bot.codeName) {
for (let k = 0; k < auxBot.products.length; k++) {
const auxProduct = auxBot.products[k]
if (auxProduct.codeName === bot.productCodeName) {
removedBotClone = auxBot
auxTeam.bots.splice(j, 1)
break
}
}
break
}
}
break
}
}
if (removedBotClone) {
await userEcosystem.save()
return removedBotClone
} else {
throw 'Algobot not found.'
}
} catch (err) {
logger.error('removeBot -> Error: %s', err.message)
throw err
}
}
const mutation = {
removeBot: {
type: BotType,
args,
resolve,
}
}
export default mutation;
+5 -1
View File
@@ -5,13 +5,17 @@ import {
import AddTeamMutation from './AddTeam'
import DeleteTeamMutation from './DeleteTeam'
import CreateFileMutation from './CreateFile'
import AddBotMutation from './AddBot'
import RemoveBotMutation from './RemoveBot'
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: Object.assign(
AddTeamMutation,
DeleteTeamMutation,
CreateFileMutation
CreateFileMutation,
AddBotMutation,
RemoveBotMutation
)
})
+5 -2
View File
@@ -8,11 +8,14 @@ const Type = new GraphQLInputObjectType({
name: 'BotInput',
description: 'Payload for bot input.',
fields: () => ({
devTeam: { type: new GraphQLNonNull(GraphQLString) },
codeName: { type: new GraphQLNonNull(GraphQLString) },
displayName: { type: new GraphQLNonNull(GraphQLString) },
productCodeName: { type: new GraphQLNonNull(GraphQLString) },
displayName: { type: GraphQLString },
repo: { type: GraphQLString },
configFile: { type: GraphQLString },
cloneId: { type: GraphQLString }
cloneId: { type: GraphQLString },
validPeriod: { type: GraphQLString },
}),
});
+19
View File
@@ -0,0 +1,19 @@
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLList
} from 'graphql';
const Type = new GraphQLInputObjectType({
name: 'DataSetInput',
description: 'Payload for data set input.',
fields: () => ({
codeName: { type: new GraphQLNonNull(GraphQLString) },
type: { type: new GraphQLNonNull(GraphQLString) },
filePath: { type: new GraphQLNonNull(GraphQLString) },
fileName: { type: new GraphQLNonNull(GraphQLString) },
validPeriods: { type: new GraphQLList(GraphQLString) }
}),
});
export default Type;
+15
View File
@@ -0,0 +1,15 @@
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLNonNull
} from 'graphql';
const Type = new GraphQLInputObjectType({
name: 'ExchangeInput',
description: 'Payload for exchange input.',
fields: () => ({
name: { type: new GraphQLNonNull(GraphQLString) }
}),
});
export default Type;
+17
View File
@@ -0,0 +1,17 @@
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLNonNull
} from 'graphql';
const Type = new GraphQLInputObjectType({
name: 'PlotterInput',
description: 'Payload for plotter input.',
fields: () => ({
devTeam: { type: new GraphQLNonNull(GraphQLString) },
codeName: { type: new GraphQLNonNull(GraphQLString) },
moduleName: { type: new GraphQLNonNull(GraphQLString) }
}),
});
export default Type;
+24
View File
@@ -0,0 +1,24 @@
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLNonNull
} from 'graphql';
import { DataSetInputType } from './index';
import { ExchangeInputType } from './index';
import { PlotterInputType } from './index';
const Type = new GraphQLInputObjectType({
name: 'ProductInput',
description: 'Payload for product input.',
fields: () => ({
codeName: { type: new GraphQLNonNull(GraphQLString) },
displayName: { type: new GraphQLNonNull(GraphQLString) },
description: { type: GraphQLString },
dataSets: { type: new GraphQLList(DataSetInputType) },
exchangeList: { type: new GraphQLList(ExchangeInputType) },
plotter: { type: PlotterInputType }
}),
});
export default Type;
+9 -1
View File
@@ -3,11 +3,19 @@ import BotInputType from './Bot'
import HostInputType from './Host'
import FileInputType from './File'
import DeleteTeamInputType from './DeleteTeam'
import DataSetInputType from './DataSet'
import ExchangeInputType from './Exchange'
import PlotterInputType from './Plotter'
import ProductInputType from './Product'
export {
TeamInputType,
BotInputType,
HostInputType,
FileInputType,
DeleteTeamInputType
DeleteTeamInputType,
DataSetInputType,
ExchangeInputType,
PlotterInputType,
ProductInputType
}