From e6f54268cc2e9d7f2f4d416f8bba7c40dbc3c53d Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 21 Feb 2019 12:12:36 +0100 Subject: [PATCH] Adapting to incorporate a selectable key system --- src/schema/mutations/RegisterToEvent.js | 74 ++++++++++--------------- src/schema/types/input/Participant.js | 6 +- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/schema/mutations/RegisterToEvent.js b/src/schema/mutations/RegisterToEvent.js index 3b0f6d1d6..4b462e2bf 100644 --- a/src/schema/mutations/RegisterToEvent.js +++ b/src/schema/mutations/RegisterToEvent.js @@ -19,7 +19,7 @@ const args = { }; const resolve = (parent, - { eventId: _id, participant: { participantId, botId } }, + { eventId: _id, participant: { keyId, participantId, botId } }, { userId, authorization }) => { if (!userId) { throw new AuthentificationError(); @@ -58,8 +58,21 @@ const resolve = (parent, method: 'post', data: { query: ` - { - keyVault_DefaultKey{ + mutation { + operations_AddClone( + clone: { + botId: "${botId}" + botType: "Trading" + mode: "competition" + resumeExecution: false + runAsTeam: true + teamId: "${participantId}" + processName: "Trading-Process" + keyId: "${keyId}" + beginDatetime: "${event.startDatetime}" + endDatetime: "${event.endDatetime}" + } + ) { id } } @@ -67,49 +80,18 @@ const resolve = (parent, }, headers: { authorization }, }).then( - (keyResult) => { - axios({ - url: process.env.GATEWAY_ENDPOINT, - method: 'post', - data: { - query: ` - mutation { - operations_AddClone( - clone: { - botId: "${botId}" - botType: "Trading" - mode: "competition" - resumeExecution: false - runAsTeam: true - teamId: "${participantId}" - processName: "${event.title}-${participantId}" - keyId: "${keyResult.data.data.keyVault_DefaultKey.id}" - } - ) { - id - } - } - `, - }, - headers: { authorization }, - }).then( - (operationCreation) => { - event.participants.push({ - participantId, - operationId: operationCreation.data.data.operations_AddClone.id, - }); - event.save((error) => { - if (error) { - rej(error); - return; - } - res(event); - }); - }, - (error) => { - rej(new ServiceUnavailableError(error)); - }, - ); + (operationCreation) => { + event.participants.push({ + participantId, + operationId: operationCreation.data.data.operations_AddClone.id, + }); + event.save((error) => { + if (error) { + rej(error); + return; + } + res(event); + }); }, (error) => { rej(new ServiceUnavailableError(error)); diff --git a/src/schema/types/input/Participant.js b/src/schema/types/input/Participant.js index 825372066..c6fa4f502 100644 --- a/src/schema/types/input/Participant.js +++ b/src/schema/types/input/Participant.js @@ -1,14 +1,16 @@ import { GraphQLInputObjectType, GraphQLString, + GraphQLNonNull, } from 'graphql'; const Type = new GraphQLInputObjectType({ name: 'ParticipantInput', description: 'Payload for formula input', fields: () => ({ - participantId: { type: GraphQLString }, - botId: { type: GraphQLString }, + participantId: { type: new GraphQLNonNull(GraphQLString) }, + keyId: { type: new GraphQLNonNull(GraphQLString) }, + botId: { type: new GraphQLNonNull(GraphQLString) }, releaseId: { type: GraphQLString }, }), });