Add and remove clones from ecosystem

This commit is contained in:
Matias committed 2019-07-03 20:13:25 -03:00
1 parent ecf365798f
commit 5cdaca4a6d
5 files changed
+122 -7

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import logger from '../config/logger'
import axios from 'axios'
const addBotMutation = async (authorization, bot) => {
logger.debug('addBotMutation -> Entering function.')
let response = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
mutation web_AddBot($bot: web_BotInput){
web_AddBot(bot: $bot){
codeName
cloneId
}
}
`,
variables: {
bot
}
},
headers: {
authorization: authorization
}
})
if (response.data.errors) {
throw response.data.errors
}
return response.data.data.web_AddBot
}
export default addBotMutation
+1 -1
View File
@@ -31,7 +31,7 @@ const ecosystemQuery = async (authorization) => {
})
if (response.data.errors) {
throw error
throw response.data.errors
}
return response.data.data.web_GetEcosystem
@@ -0,0 +1,35 @@
import logger from '../config/logger'
import axios from 'axios'
const removeBotMutation = async (authorization, bot) => {
logger.debug('removeBotMutation -> Entering function.')
let response = await axios({
url: process.env.GATEWAY_ENDPOINT,
method: 'post',
data: {
query: `
mutation web_RemoveBot($bot: web_BotInput){
web_RemoveBot(bot: $bot){
codeName
cloneId
}
}
`,
variables: {
bot
}
},
headers: {
authorization: authorization
}
})
if (response.data.errors) {
throw response.data.errors
}
return response.data.data.web_RemoveBot
}
export default removeBotMutation
@@ -1,10 +1,10 @@
import { CloneInputType } from '../types/input'
import { CloneType } from '../types'
import { Clone } from '../../models'
import { CloneModeEnum } from '../../enums/CloneMode'
import { BotTypesEnum } from '../../enums/BotTypes'
import teamQuery from '../../graphQLCalls/teamQuery'
import authorizeKey from '../../graphQLCalls/authorizeKey'
import addBotMutation from '../../graphQLCalls/addBotMutation'
import cloneDetails from '../cloneDetails'
import {
AuthenticationError,
@@ -15,7 +15,8 @@ import {
import logger from '../../config/logger'
import createKubernetesClone from '../../kubernetes/createClone'
import { isDefined } from '../../config/utils'
import { LIVE, COMPETITION } from '../../enums/CloneMode'
import { CloneModeEnum, LIVE, COMPETITION, BACKTEST } from '../../enums/CloneMode'
import { Trading } from '../../enums/BotTypes'
const args = {
clone: { type: CloneInputType }
@@ -93,6 +94,28 @@ const resolve = async (parent, { clone }, context) => {
await createKubernetesClone(clone)
if(clone.botType === Trading){
let productCodeName
if(clone.mode === LIVE){
productCodeName = 'Live Trading History'
}
if(clone.mode === COMPETITION){
productCodeName = 'Competition Trading History'
}
if(clone.mode === BACKTEST){
productCodeName = 'Backtest Trading History'
}
let newEcosystemBot = {
devTeam: clone.teamSlug,
codeName: clone.botSlug,
cloneId: clone.id,
productCodeName
}
await addBotMutation(context.authorization, newEcosystemBot)
}
logger.debug('addClone -> Clone created sucessfully.')
return savedClone
} catch (err) {
@@ -7,11 +7,11 @@ import teamQuery from '../../graphQLCalls/teamQuery'
import { isDefined } from '../../config/utils'
import cloneDetails from '../cloneDetails'
import authorizeKey from '../../graphQLCalls/authorizeKey'
import { LIVE, COMPETITION } from '../../enums/CloneMode'
import { LIVE, COMPETITION, BACKTEST } from '../../enums/CloneMode'
import { Trading } from '../../enums/BotTypes'
import removeBotMutation from '../../graphQLCalls/removeBotMutation'
const args = {
id: { type: new GraphQLNonNull(GraphQLID) }
}
const args = { id: { type: new GraphQLNonNull(GraphQLID) } }
const resolve = async (parent, { id }, context) => {
logger.debug('removeClone -> Entering Fuction.')
@@ -42,6 +42,28 @@ const resolve = async (parent, { id }, context) => {
logger.debug('removeClone -> Removing Clone from Kubernates.')
await removeKuberneteClone(clone.id)
if (clone.botType === Trading) {
let productCodeName
if (clone.mode === LIVE) {
productCodeName = 'Live Trading History'
}
if (clone.mode === COMPETITION) {
productCodeName = 'Competition Trading History'
}
if (clone.mode === BACKTEST) {
productCodeName = 'Backtest Trading History'
}
let newEcosystemBot = {
devTeam: clone.teamSlug,
codeName: clone.botSlug,
cloneId: clone.id,
productCodeName
}
await removeBotMutation(context.authorization, newEcosystemBot)
}
const query = {
_id: id,
authId: context.userId