From a73805f222c008559b504aea0011eaf8cbc43549 Mon Sep 17 00:00:00 2001 From: Matias Date: Wed, 27 Mar 2019 19:38:42 +0100 Subject: [PATCH] Clone Details method update --- server/src/kubernetes/createClone.js | 2 +- server/src/schema/cloneDetails.js | 16 +++------------- server/src/schema/mutations/AddCloneMutation.js | 5 +++-- .../src/schema/mutations/RemoveCloneMutation.js | 5 +++-- .../schema/mutations/UpdateExecutionSummary.js | 5 +++-- server/src/schema/queries/HistoryClones.js | 2 +- server/src/schema/queries/ListClones.js | 2 +- 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/server/src/kubernetes/createClone.js b/server/src/kubernetes/createClone.js index 775888a4e..cf5927177 100644 --- a/server/src/kubernetes/createClone.js +++ b/server/src/kubernetes/createClone.js @@ -159,7 +159,7 @@ const createClone = async (clone) => { } deploymentManifest.spec.template.spec.containers[0].env = env - + logger.debug('ENV %s: ', JSON.stringify(env)) await client.apis.batch.v1.namespaces('default').jobs.post( { body: deploymentManifest }) diff --git a/server/src/schema/cloneDetails.js b/server/src/schema/cloneDetails.js index ae5d37f1b..d0dff70b3 100644 --- a/server/src/schema/cloneDetails.js +++ b/server/src/schema/cloneDetails.js @@ -1,26 +1,16 @@ -import logger from '../config/logger' - -const cloneDetails = (authId, selectedBot, clone) => { - logger.debug('cloneDetails -> Entering function.') - +const cloneDetails = (selectedBot, clone) => { if (selectedBot !== undefined) { clone.botId = selectedBot.id clone.kind = selectedBot.kind clone.botName = selectedBot.name clone.botSlug = selectedBot.slug clone.botAvatar = selectedBot.avatar - clone.teamId = selectedBot.team.id clone.teamName = selectedBot.team.name clone.teamSlug = selectedBot.team.slug - clone.teamAvatar = selectedBot.team.profile.avatar - - clone.userLoggedIn = selectedBot.team.members[0].member.alias // TODO change by context info if possible - - clone.botType = selectedBot.kind // Only for listing we show the teams value - - logger.debug('cloneDetails -> Retrieving clone details complete.') + clone.userLoggedIn = selectedBot.team.members[0].member.alias + clone.botType = selectedBot.kind } return clone } diff --git a/server/src/schema/mutations/AddCloneMutation.js b/server/src/schema/mutations/AddCloneMutation.js index edaf47e4d..549f9651f 100644 --- a/server/src/schema/mutations/AddCloneMutation.js +++ b/server/src/schema/mutations/AddCloneMutation.js @@ -41,8 +41,9 @@ const resolve = async (parent, { clone }, context) => { } try { - let team = await teamQuery(context.authorization, clone.teamId) - clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone) + let allUserBotsResponse = await teamQuery(context.authorization, clone.botId) + let bot = allUserBotsResponse.data.data.teams_FbByOwner.edges[0].node + clone = cloneDetails(bot, clone) clone.createDatetime = new Date().valueOf() / 1000 | 0 clone.active = true diff --git a/server/src/schema/mutations/RemoveCloneMutation.js b/server/src/schema/mutations/RemoveCloneMutation.js index 43eebde78..5e4fa9ed0 100644 --- a/server/src/schema/mutations/RemoveCloneMutation.js +++ b/server/src/schema/mutations/RemoveCloneMutation.js @@ -30,8 +30,9 @@ const resolve = async (parent, { id }, context) => { throw new OperationsError('You are not authorized to remove this clone.') } - let team = await teamQuery(context.authorization, clone.teamId) - clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone) + let allUserBotsResponse = await teamQuery(context.authorization, clone.botId) + let bot = allUserBotsResponse.data.data.teams_FbByOwner.edges[0].node + clone = cloneDetails(bot, clone) if ((clone.mode === LIVE || clone.mode === COMPETITION) && isDefined(clone.keyId)) { logger.debug('removeClone -> Release the clone key.') diff --git a/server/src/schema/mutations/UpdateExecutionSummary.js b/server/src/schema/mutations/UpdateExecutionSummary.js index dfe434e7d..de5729f6d 100644 --- a/server/src/schema/mutations/UpdateExecutionSummary.js +++ b/server/src/schema/mutations/UpdateExecutionSummary.js @@ -44,8 +44,9 @@ const resolve = async (parent, return 'Clone not found.' } - let team = await teamQuery(context.authorization, clone.teamId) - clone = await cloneDetails(context.userId, team.data.data.teams_TeamById, clone) + let allUserBotsResponse = await teamQuery(context.authorization, clone.botId) + let bot = allUserBotsResponse.data.data.teams_FbByOwner.edges[0].node + clone = cloneDetails(bot, clone) const query = { _id: id } const options = { new: true } diff --git a/server/src/schema/queries/HistoryClones.js b/server/src/schema/queries/HistoryClones.js index 446124699..f9a3ee731 100644 --- a/server/src/schema/queries/HistoryClones.js +++ b/server/src/schema/queries/HistoryClones.js @@ -30,7 +30,7 @@ const resolve = async(parent, { botType }, context) => { for (var j = 0; j < allUserBots.length; j++) { let bot = allUserBots[j].node if(clones[i].botId === bot.id){ - let clone = cloneDetails(context.userId, bot, clones[i]) + let clone = cloneDetails(bot, clones[i]) cloneResponse.push(clone) break } diff --git a/server/src/schema/queries/ListClones.js b/server/src/schema/queries/ListClones.js index 390201f17..60f5e4e1a 100644 --- a/server/src/schema/queries/ListClones.js +++ b/server/src/schema/queries/ListClones.js @@ -33,7 +33,7 @@ const resolve = async (parent, { botType, queryLogs }, context) => { for (var j = 0; j < allUserBots.length; j++) { let bot = allUserBots[j].node if(clones[i].botId === bot.id){ - let clone = cloneDetails(context.userId, bot, clones[i]) + let clone = cloneDetails(bot, clones[i]) cloneResponse.push(clone) break }