From 7f5b093de0bec372bca00206528aa2a68a848000 Mon Sep 17 00:00:00 2001 From: Matias Date: Mon, 27 May 2019 13:48:51 -0300 Subject: [PATCH] Progress pre master app --- src/models/ecosystem.js | 204 ++++++++++++++++++++++++++- src/schema/mutations/AddTeam.js | 25 +++- src/schema/mutations/DeleteTeam.js | 6 +- src/schema/types/Bot.js | 14 +- src/schema/types/Competition.js | 32 +++++ src/schema/types/DataRange.js | 14 ++ src/schema/types/DataSet.js | 21 +++ src/schema/types/Ecosystem.js | 4 +- src/schema/types/EventHost.js | 17 ++- src/schema/types/Exchange.js | 13 ++ src/schema/types/Module.js | 25 ++++ src/schema/types/Panel.js | 15 ++ src/schema/types/Plotter.js | 26 ++++ src/schema/types/PlotterReference.js | 17 +++ src/schema/types/Product.js | 31 ++++ src/schema/types/Team.js | 6 +- src/schema/types/index.js | 20 ++- 17 files changed, 464 insertions(+), 26 deletions(-) create mode 100644 src/schema/types/Competition.js create mode 100644 src/schema/types/DataRange.js create mode 100644 src/schema/types/DataSet.js create mode 100644 src/schema/types/Exchange.js create mode 100644 src/schema/types/Module.js create mode 100644 src/schema/types/Panel.js create mode 100644 src/schema/types/Plotter.js create mode 100644 src/schema/types/PlotterReference.js create mode 100644 src/schema/types/Product.js diff --git a/src/models/ecosystem.js b/src/models/ecosystem.js index 5856d8f19..36ce90642 100644 --- a/src/models/ecosystem.js +++ b/src/models/ecosystem.js @@ -6,7 +6,7 @@ const ecosystemSchema = new Schema({ type: String, required: true }, - teams: [{ + devTeams: [{ codeName: { type: String, required: true @@ -15,7 +15,7 @@ const ecosystemSchema = new Schema({ type: String, required: true }, - host:{ + host: { url: { type: String, required: true @@ -42,6 +42,10 @@ const ecosystemSchema = new Schema({ type: String, required: true }, + type: { + type: String, + required: false + }, repo: { type: String, required: false @@ -49,9 +53,115 @@ const ecosystemSchema = new Schema({ configFile: { type: String, required: false - } + }, + products: [{ + codeName: { + type: String, + required: true + }, + displayName: { + type: String, + required: true + }, + description: { + type: String, + required: true + }, + dataSets: [{ + codeName: { + type: String, + required: true + }, + type: { + type: String, + required: true + }, + validPeriods: [{ + type: String, + required: true + }], + filePath: { + type: String, + required: true + }, + fileName: { + type: String, + required: true + }, + dataRange: { + filePath: { + type: String, + required: false + }, + fileName: { + type: String, + required: false + }, + }, + }], + exchangeList: [{ + name: { + type: String, + required: true + } + }], + plotter: { + codeName: { + type: String, + required: false + }, + devTeam: { + type: String, + required: false + }, + moduleName: { + type: String, + required: true + }, + } + }] }], plotters: [{ + codeName: { + type: String, + required: true + }, + displayName: { + type: String, + required: true + }, + modules: [{ + codeName: { + type: String, + required: true + }, + moduleName: { + type: String, + required: true + }, + description: { + type: String, + required: false + }, + profilePicture: { + type: String, + required: false + }, + panels: [{ + codeName: { + type: String, + required: true + }, + moduleName: { + type: String, + required: true + }, + event: { + type: String, + required: true + } + }], + }], repo: { type: String, required: true @@ -71,7 +181,7 @@ const ecosystemSchema = new Schema({ type: String, required: true }, - host:{ + host: { url: { type: String, required: true @@ -90,6 +200,52 @@ const ecosystemSchema = new Schema({ } }, competitions: [{ + codeName: { + type: String, + required: true + }, + displayName: { + type: String, + required: true + }, + description: { + type: String, + required: false + }, + startDatetime: { + type: String, + required: false + }, + finishDatetime: { + type: String, + required: false + }, + formula: { + type: String, + required: false + }, + plotter: { + codeName: { + type: String, + required: false + }, + host: { + type: String, + required: false + }, + repo: { + type: String, + required: true + }, + moduleName: { + type: String, + required: true + }, + }, + participants: [{ + type: String, + required: false + }], repo: { type: String, required: true @@ -100,6 +256,46 @@ const ecosystemSchema = new Schema({ } }], plotters: [{ + codeName: { + type: String, + required: true + }, + displayName: { + type: String, + required: true + }, + modules: [{ + codeName: { + type: String, + required: true + }, + moduleName: { + type: String, + required: true + }, + description: { + type: String, + required: false + }, + profilePicture: { + type: String, + required: false + }, + panels: [{ + codeName: { + type: String, + required: true + }, + moduleName: { + type: String, + required: true + }, + event: { + type: String, + required: true + } + }], + }], repo: { type: String, required: true diff --git a/src/schema/mutations/AddTeam.js b/src/schema/mutations/AddTeam.js index 44e6402d0..87e339e94 100644 --- a/src/schema/mutations/AddTeam.js +++ b/src/schema/mutations/AddTeam.js @@ -27,8 +27,8 @@ const resolve = async (parent, { team }, context) => { userEcosystem.authId = context.userId } - for (let i = 0; i < userEcosystem.teams.length; i++) { - const auxTeam = userEcosystem.teams[i]; + for (let i = 0; i < userEcosystem.devTeams.length; i++) { + const auxTeam = userEcosystem.devTeams[i]; if (auxTeam.codeName === team.codeName) { throw new WrongArgumentsError("The team already exist on the user ecosystem.") } @@ -44,11 +44,26 @@ const resolve = async (parent, { team }, context) => { team.host = nodeEndpoint } - let bots= [] - bots.push(team.bot) + let bots = [] + let tradingBot = { + codeName: team.bot.codeName, + displayName: team.bot.displayName, + repo: team.bot.codeName + '-Trading-Bot', + configFile: 'this.bot.config.json' + } + bots.push(tradingBot) + + let simulatorBot = { + codeName: 'simulator-' + team.bot.codeName, + displayName: 'Simulator ' + team.bot.displayName, + repo: 'simulator-' + team.bot.codeName + '-Indicator-Bot', + configFile: 'this.bot.config.json' + } + bots.push(simulatorBot) + team.bots = bots - userEcosystem.teams.push(team) + userEcosystem.devTeams.push(team) await userEcosystem.save() return team } catch (err) { diff --git a/src/schema/mutations/DeleteTeam.js b/src/schema/mutations/DeleteTeam.js index 85f4c403a..dd4061919 100644 --- a/src/schema/mutations/DeleteTeam.js +++ b/src/schema/mutations/DeleteTeam.js @@ -25,13 +25,13 @@ const resolve = async (parent, { team }, context) => { } let teamFound = false - for (let i = 0; i < userEcosystem.teams.length; i++) { - const auxTeam = userEcosystem.teams[i] + for (let i = 0; i < userEcosystem.devTeams.length; i++) { + const auxTeam = userEcosystem.devTeams[i] if (auxTeam.codeName === team.codeName) { logger.debug('deleteTeam -> Team found, removing.') teamFound = true await deleteTeam(team) - userEcosystem.teams.splice(i, 1) + userEcosystem.devTeams.splice(i, 1) await userEcosystem.save() break } diff --git a/src/schema/types/Bot.js b/src/schema/types/Bot.js index 6701c467e..f983f1129 100644 --- a/src/schema/types/Bot.js +++ b/src/schema/types/Bot.js @@ -1,15 +1,25 @@ import { GraphQLObjectType, - GraphQLString + GraphQLString, + GraphQLList } from 'graphql'; +import { ProductType } from './index' + const BotType = new GraphQLObjectType({ name: 'Bot', fields: () => ({ codeName: { type: GraphQLString }, displayName: { type: GraphQLString }, + type: { type: GraphQLString }, repo: { type: GraphQLString }, - configFile: { type: GraphQLString } + configFile: { type: GraphQLString }, + products: { + type: new GraphQLList(ProductType), + resolve(parent) { + return parent.products; + } + }, }), }); diff --git a/src/schema/types/Competition.js b/src/schema/types/Competition.js new file mode 100644 index 000000000..16f42cd4a --- /dev/null +++ b/src/schema/types/Competition.js @@ -0,0 +1,32 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList +} from 'graphql'; + +import { PlotterReferenceType } from './index'; + +const CompetitionType = new GraphQLObjectType({ + name: 'Competition', + fields: () => ({ + codeName: { type: GraphQLString }, + displayName: { type: GraphQLString }, + description: { type: GraphQLString }, + startDatetime: { type: GraphQLString }, + finishDatetime: { type: GraphQLString }, + formula: { type: GraphQLString }, + plotter: { + type: PlotterReferenceType, + resolve(parent) { + return parent.plotter; + } + }, + rules:{ type: new GraphQLList(GraphQLString) }, + prizes:{ type: new GraphQLList(GraphQLString) }, + participants:{ type: new GraphQLList(GraphQLString) }, + repo: { type: GraphQLString }, + configFile: { type: GraphQLString } + }), +}); + +export default CompetitionType; diff --git a/src/schema/types/DataRange.js b/src/schema/types/DataRange.js new file mode 100644 index 000000000..aebeb3cd7 --- /dev/null +++ b/src/schema/types/DataRange.js @@ -0,0 +1,14 @@ +import { + GraphQLObjectType, + GraphQLString +} from 'graphql'; + +const DataRangeType = new GraphQLObjectType({ + name: 'DataRange', + fields: () => ({ + filePath: { type: GraphQLString }, + fileName: { type: GraphQLString } + }), +}); + +export default DataRangeType; diff --git a/src/schema/types/DataSet.js b/src/schema/types/DataSet.js new file mode 100644 index 000000000..a96ff8ff5 --- /dev/null +++ b/src/schema/types/DataSet.js @@ -0,0 +1,21 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList +} from 'graphql'; + +import { DataRangeType } from './index' + +const DataSetType = new GraphQLObjectType({ + name: 'DataSet', + fields: () => ({ + codeName: { type: GraphQLString }, + type: { type: GraphQLString }, + validPeriods: { type: new GraphQLList(GraphQLString) }, + filePath: { type: GraphQLString }, + fileName: { type: GraphQLString }, + dataRange: { type: DataRangeType } + }), +}); + +export default DataSetType; diff --git a/src/schema/types/Ecosystem.js b/src/schema/types/Ecosystem.js index d31cbbde2..8fabc5847 100644 --- a/src/schema/types/Ecosystem.js +++ b/src/schema/types/Ecosystem.js @@ -13,10 +13,10 @@ const EcosystemType = new GraphQLObjectType({ id: { type: GraphQLID }, authId: { type: GraphQLString }, userName: { type: GraphQLString }, // TODO this field is temporary, it should be used the user module query - teams: { + devTeams: { type: new GraphQLList(TeamType), resolve(parent) { - return parent.teams; + return parent.devTeams; } }, hosts: { diff --git a/src/schema/types/EventHost.js b/src/schema/types/EventHost.js index 571bab36e..c951dabba 100644 --- a/src/schema/types/EventHost.js +++ b/src/schema/types/EventHost.js @@ -4,26 +4,31 @@ import { GraphQLList } from 'graphql'; -import { BotType } from './index'; +import { CompetitionType, PlotterType, HostType } from './index'; const EventHostType = new GraphQLObjectType({ name: 'EventHost', fields: () => ({ codeName: { type: GraphQLString }, displayName: { type: GraphQLString }, - host: { type: GraphQLString }, + host: { + type: HostType, + resolve(parent) { + return parent.host; + } + }, container: { type: GraphQLString }, accessKey: { type: GraphQLString }, competitions: { - type: new GraphQLList(BotType), + type: new GraphQLList(CompetitionType), resolve(parent) { - return parent.bots; + return parent.competitions; } }, plotters: { - type: new GraphQLList(BotType), + type: new GraphQLList(PlotterType), resolve(parent) { - return parent.bots; + return parent.plotters; } } }), diff --git a/src/schema/types/Exchange.js b/src/schema/types/Exchange.js new file mode 100644 index 000000000..b80b7ec03 --- /dev/null +++ b/src/schema/types/Exchange.js @@ -0,0 +1,13 @@ +import { + GraphQLObjectType, + GraphQLString +} from 'graphql'; + +const ExchangeType = new GraphQLObjectType({ + name: 'Exchange', + fields: () => ({ + name: { type: GraphQLString } + }), +}); + +export default ExchangeType; diff --git a/src/schema/types/Module.js b/src/schema/types/Module.js new file mode 100644 index 000000000..eb1addabb --- /dev/null +++ b/src/schema/types/Module.js @@ -0,0 +1,25 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList +} from 'graphql' + +import { PanelType } from './index' + +const ModuleType = new GraphQLObjectType({ + name: 'Module', + fields: () => ({ + codeName: { type: GraphQLString }, + moduleName: { type: GraphQLString }, + description: { type: GraphQLString }, + profilePicture: { type: GraphQLString }, + panels: { + type: new GraphQLList(PanelType), + resolve(parent) { + return parent.panels; + } + } + }), +}); + +export default ModuleType; diff --git a/src/schema/types/Panel.js b/src/schema/types/Panel.js new file mode 100644 index 000000000..a3e19b4aa --- /dev/null +++ b/src/schema/types/Panel.js @@ -0,0 +1,15 @@ +import { + GraphQLObjectType, + GraphQLString +} from 'graphql'; + +const PanelType = new GraphQLObjectType({ + name: 'Panel', + fields: () => ({ + codeName: { type: GraphQLString }, + moduleName: { type: GraphQLString }, + event: { type: GraphQLString } + }), +}); + +export default PanelType; diff --git a/src/schema/types/Plotter.js b/src/schema/types/Plotter.js new file mode 100644 index 000000000..b0b672625 --- /dev/null +++ b/src/schema/types/Plotter.js @@ -0,0 +1,26 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList +} from 'graphql'; + +import { ModuleType } from './index' + +const PlotterType = new GraphQLObjectType({ + name: 'Plotter', + fields: () => ({ + codeName: { type: GraphQLString }, + displayName: { type: GraphQLString }, + host: { type: GraphQLString }, + modules: { + type: new GraphQLList(ModuleType), + resolve(parent) { + return parent.modules; + } + }, + repo: { type: GraphQLString }, + configFile: { type: GraphQLString } + }), +}); + +export default PlotterType; diff --git a/src/schema/types/PlotterReference.js b/src/schema/types/PlotterReference.js new file mode 100644 index 000000000..1c6007032 --- /dev/null +++ b/src/schema/types/PlotterReference.js @@ -0,0 +1,17 @@ +import { + GraphQLObjectType, + GraphQLString +} from 'graphql'; + +const PlotterReferenceType = new GraphQLObjectType({ + name: 'PlotterReference', + fields: () => ({ + codeName: { type: GraphQLString }, + host: { type: GraphQLString }, + devTeam: { type: GraphQLString }, + moduleName: { type: GraphQLString }, + repo: { type: GraphQLString } + }), +}); + +export default PlotterReferenceType; diff --git a/src/schema/types/Product.js b/src/schema/types/Product.js new file mode 100644 index 000000000..1494872c3 --- /dev/null +++ b/src/schema/types/Product.js @@ -0,0 +1,31 @@ +import { + GraphQLObjectType, + GraphQLString, + GraphQLList +} from 'graphql'; + +import { ExchangeType, DataSetType, PlotterReferenceType } from './index' + +const ProductType = new GraphQLObjectType({ + name: 'Product', + fields: () => ({ + codeName: { type: GraphQLString }, + displayName: { type: GraphQLString }, + description: { type: GraphQLString }, + dataSets: { + type: new GraphQLList(DataSetType), + resolve(parent) { + return parent.dataSets; + } + }, + exchangeList: { + type: new GraphQLList(ExchangeType), + resolve(parent) { + return parent.exchangeList; + } + }, + plotter: { type: PlotterReferenceType } + }), +}); + +export default ProductType; diff --git a/src/schema/types/Team.js b/src/schema/types/Team.js index e39d0aa5b..00607f192 100644 --- a/src/schema/types/Team.js +++ b/src/schema/types/Team.js @@ -4,7 +4,7 @@ import { GraphQLList } from 'graphql'; -import { BotType, HostType } from './index'; +import { BotType, PlotterType, HostType } from './index'; const TeamType = new GraphQLObjectType({ name: 'Team', @@ -24,9 +24,9 @@ const TeamType = new GraphQLObjectType({ } }, plotters: { - type: new GraphQLList(BotType), + type: new GraphQLList(PlotterType), resolve(parent) { - return parent.bots; + return parent.plotters; } } }), diff --git a/src/schema/types/index.js b/src/schema/types/index.js index 17d90c59a..31708e9b2 100644 --- a/src/schema/types/index.js +++ b/src/schema/types/index.js @@ -4,6 +4,15 @@ import EventHostType from './EventHost'; import HostType from './Host'; import EcosystemType from './Ecosystem'; import FileType from './File'; +import PanelType from './Panel'; +import ModuleType from './Module'; +import PlotterType from './Plotter'; +import CompetitionType from './Competition'; +import PlotterReferenceType from './PlotterReference'; +import ProductType from './Product'; +import DataSetType from './DataSet'; +import DataRangeType from './DataRange'; +import ExchangeType from './Exchange'; export { TeamType, @@ -11,5 +20,14 @@ export { EventHostType, HostType, EcosystemType, - FileType + FileType, + PanelType, + ModuleType, + PlotterType, + CompetitionType, + PlotterReferenceType, + ProductType, + DataSetType, + DataRangeType, + ExchangeType };