Merge pull request #15 from nikolabjelo/master
Huge backend modification with a lot of breaking changes
This commit is contained in:
90 files changed
+2671
-1517
No files matched your search
+3
-1
@@ -1,3 +1,5 @@
|
||||
PRESHARED_GATEWAY_KEY=SECRET_STUFF
|
||||
|
||||
PORT=3000
|
||||
DB_USERNAME=example_name
|
||||
DB_PASSWORD=example_password
|
||||
@@ -5,4 +7,4 @@ DB_DOMAIN=example.com:1234/example_name
|
||||
|
||||
SENTRY_DNS=https://some-val@sentry.io/some-id
|
||||
|
||||
TEAMS_ENDPOINT=https://teams-api.advancedalgos.net/graphql/
|
||||
GATEWAY_ENDPOINT=https://app-api.advancedalgos.net/graphql/
|
||||
+2
-1
@@ -2,7 +2,8 @@ module.exports = {
|
||||
parser: 'babel-eslint',
|
||||
extends: 'airbnb-base',
|
||||
rules: {
|
||||
'max-len': ['error', 140, 2],
|
||||
'no-underscore-dangle': 'off',
|
||||
'no-param-reassign': 'off'
|
||||
'no-param-reassign': 'off',
|
||||
}
|
||||
};
|
||||
Generated
+748
-299
File diff suppressed because it is too large.
Load diff
+1
-3
@@ -26,13 +26,11 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/node": "^4.1.1",
|
||||
"apollo-server-express": "^2.1.0",
|
||||
"axios": "^0.18.0",
|
||||
"cors": "^2.8.4",
|
||||
"dotenv": "^6.0.0",
|
||||
"express": "^4.16.3",
|
||||
"express-graphql": "^0.6.12",
|
||||
"graphql": "^14.0.0",
|
||||
"graphql-playground-middleware-express": "^1.7.6",
|
||||
"mongoose": "^5.3.4"
|
||||
}
|
||||
}
|
||||
+29
-18
@@ -1,10 +1,9 @@
|
||||
import 'dotenv/config';
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import graphqlHTTP from 'express-graphql';
|
||||
import expressPlayground from 'graphql-playground-middleware-express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import schema from './schema';
|
||||
import wrongPreshared from './errors/notAllowed.json';
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -12,27 +11,39 @@ const app = express();
|
||||
Sentry.init({ dsn: process.env.SENTRY_DNS });
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
|
||||
// authorising CORS
|
||||
app.use(cors());
|
||||
app.post('/graphql', (req, res, next) => {
|
||||
if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) {
|
||||
next();
|
||||
} else {
|
||||
res.send(wrongPreshared);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Starting the graphql server
|
||||
app.use('/graphql', graphqlHTTP(req => ({
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
context: {
|
||||
playground: {
|
||||
settings: {
|
||||
'editor.theme': 'dark',
|
||||
'editor.cursorShape': 'line',
|
||||
},
|
||||
},
|
||||
context: ({ req }) => ({
|
||||
userId: req.headers.userid,
|
||||
authorization: req.headers.authorization,
|
||||
},
|
||||
formatError(err) {
|
||||
return {
|
||||
message: err.message,
|
||||
code: err.originalError && err.originalError.code,
|
||||
path: err.path,
|
||||
};
|
||||
},
|
||||
})));
|
||||
}),
|
||||
formatError: error => ({
|
||||
code: error.extensions.exception.code,
|
||||
message: error.message,
|
||||
path: error.path,
|
||||
}),
|
||||
});
|
||||
|
||||
// Starting the graphql server
|
||||
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
|
||||
server.applyMiddleware({
|
||||
app,
|
||||
cors: true,
|
||||
});
|
||||
|
||||
// Sentry error handling middleware if anything pass through
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dotenv/config';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
mongoose.connect(`mongodb://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_DOMAIN}`, { useNewUrlParser: true });
|
||||
mongoose.set('useCreateIndex', true);
|
||||
mongoose.set('useFindAndModify', false);
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
const db = mongoose.connection;
|
||||
|
||||
@@ -4,14 +4,16 @@ export const CANCELLED = 'CANCELLED';
|
||||
export const RUNNING = 'RUNNING';
|
||||
export const INTERRUPTED = 'INTERRUPTED';
|
||||
export const FINISHED = 'FINISHED';
|
||||
export const ARCHIVED = 'ARCHIVED';
|
||||
|
||||
export const EventStatusEnum = [
|
||||
export const EventStateEnum = [
|
||||
UNPUBLISHED,
|
||||
PUBLISHED,
|
||||
CANCELLED,
|
||||
RUNNING,
|
||||
INTERRUPTED,
|
||||
FINISHED,
|
||||
ARCHIVED,
|
||||
];
|
||||
|
||||
export default EventStatusEnum;
|
||||
export default EventStateEnum;
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 401,
|
||||
"message": "Wait, you're not supposed to be here, go through the gate as everyone else"
|
||||
}
|
||||
]
|
||||
}
|
||||
+74
-21
@@ -3,45 +3,98 @@ import Plotter from './plotter';
|
||||
import Formula from './formula';
|
||||
import {
|
||||
UNPUBLISHED,
|
||||
EventStatusEnum,
|
||||
} from '../enums/EventStatus';
|
||||
EventStateEnum,
|
||||
} from '../enums/EventState';
|
||||
|
||||
const { ObjectId } = Schema.Types;
|
||||
|
||||
const eventSchema = new Schema({
|
||||
designator: { type: String, required: true },
|
||||
status: { type: String, enum: EventStatusEnum, default: UNPUBLISHED },
|
||||
name: { type: String, required: true },
|
||||
hostId: { type: String, required: true },
|
||||
description: String,
|
||||
startDatetime: { type: Number, required: true },
|
||||
finishDatetime: { type: Number, required: true },
|
||||
formula: { type: Schema.Types.ObjectId, ref: Formula.modelName },
|
||||
plotter: { type: Schema.Types.ObjectId, ref: Plotter.modelName },
|
||||
state: {
|
||||
type: String,
|
||||
enum: EventStateEnum,
|
||||
default: UNPUBLISHED,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
hostId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
startDatetime: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
finishDatetime: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
formulaId: {
|
||||
type: ObjectId,
|
||||
ref: Formula.modelName,
|
||||
},
|
||||
plotterId: {
|
||||
type: ObjectId,
|
||||
ref: Plotter.modelName,
|
||||
},
|
||||
rules: [{
|
||||
position: { type: Number, required: true },
|
||||
title: { type: String, required: true },
|
||||
description: String,
|
||||
position: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
prizes: [{
|
||||
rank: { type: Number, required: true },
|
||||
amount: { type: Number, required: true },
|
||||
rank: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
additional: [{
|
||||
condition: String,
|
||||
amount: { type: Number, required: true },
|
||||
asset: { type: String, required: true },
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
asset: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
}],
|
||||
}],
|
||||
participants: [{
|
||||
teamId: { type: String, required: true },
|
||||
teamId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
botId: String,
|
||||
releaseId: String,
|
||||
}],
|
||||
});
|
||||
|
||||
eventSchema.pre('find', function populate() {
|
||||
this.populate('formula').populate('plotter');
|
||||
this.populate('formulaId').populate('plotterId');
|
||||
});
|
||||
eventSchema.post('save', (doc, next) => {
|
||||
doc.populate('formula').populate('plotter').execPopulate().then(() => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
eventSchema.post('findOneAndUpdate', (doc, next) => {
|
||||
doc.populate('formulaId').populate('plotterId').execPopulate().then(() => {
|
||||
next();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
|
||||
const formulaSchema = new Schema({
|
||||
ownerId: { type: String, required: true },
|
||||
isTemplate: { type: Boolean, default: false },
|
||||
name: { type: String, required: true },
|
||||
ownerId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
isTemplate: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const Formula = mongoose.model('Formula', formulaSchema);
|
||||
|
||||
@@ -1,12 +1,30 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
|
||||
const plotterSchema = new Schema({
|
||||
ownerId: { type: String, required: true },
|
||||
isTemplate: { type: Boolean, default: false },
|
||||
name: { type: String, required: true },
|
||||
host: { type: String, required: true },
|
||||
repo: { type: String, required: true },
|
||||
moduleName: { type: String, required: true },
|
||||
ownerId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
isTemplate: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
host: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
repo: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
moduleName: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
|
||||
const Plotter = mongoose.model('Plotter', plotterSchema);
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLInt,
|
||||
} from 'graphql';
|
||||
import {
|
||||
AuthentificationError,
|
||||
DatabaseError,
|
||||
WrongArgumentsError,
|
||||
} from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
rank: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventDesignator, rank, amount }, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
if (event.prizes.some(prize => prize.rank === rank)) {
|
||||
rej(new WrongArgumentsError('A prize for that rank already exists'));
|
||||
return;
|
||||
}
|
||||
event.prizes.push({
|
||||
rank,
|
||||
amount,
|
||||
});
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
addPrize: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,70 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import {
|
||||
AuthentificationError,
|
||||
DatabaseError,
|
||||
WrongArgumentsError,
|
||||
} from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
title: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: new GraphQLNonNull(GraphQLString) },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventDesignator, title, description }, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
if (event.rules.some(rule => rule.title === title)) {
|
||||
rej(new WrongArgumentsError('A prize for that rank already exists'));
|
||||
return;
|
||||
}
|
||||
const isFree = pos => event.rules.some(rule => rule.pos === pos);
|
||||
let position = 1;
|
||||
let shouldGrow = isFree(position);
|
||||
while (shouldGrow) {
|
||||
position += 1;
|
||||
shouldGrow = isFree(position);
|
||||
}
|
||||
event.rules.push({
|
||||
position,
|
||||
title,
|
||||
description,
|
||||
});
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
addRule: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import EventStateEnum from '../types/enum/EventState';
|
||||
|
||||
const args = {
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
state: { type: EventStateEnum },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventId: _id, state }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOneAndUpdate({ _id, hostId }, { state }, { new: true }, (err, modifiedEvent) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(modifiedEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
changeEventState: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,56 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event, Formula } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLString) },
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
};
|
||||
|
||||
const resolve = (parent, { name, eventDesignator }, context) => {
|
||||
const ownerId = context.userId;
|
||||
if (!ownerId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
const newFormula = new Formula({ name, ownerId });
|
||||
return new Promise((res, reject) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId: ownerId }).exec((err, event) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
reject(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
newFormula.save((error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
event.formula = newFormula._id;
|
||||
event.save((eventError) => {
|
||||
if (eventError) {
|
||||
reject(eventError);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
createAndSetFormula: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,65 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event, Plotter } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLString) },
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
host: { type: new GraphQLNonNull(GraphQLString) },
|
||||
repo: { type: new GraphQLNonNull(GraphQLString) },
|
||||
moduleName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
name, host, repo, moduleName, eventDesignator,
|
||||
}, context) => {
|
||||
const ownerId = context.userId;
|
||||
if (!ownerId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
const newPlotter = new Plotter({
|
||||
name, host, repo, moduleName, ownerId,
|
||||
});
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId: ownerId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
|
||||
newPlotter.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
|
||||
event.plotter = newPlotter._id;
|
||||
event.save((eventError) => {
|
||||
if (eventError) {
|
||||
rej(eventError);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
createAndSetPlotter: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { EventInputType } from '../types/input';
|
||||
|
||||
export const args = {
|
||||
event: { type: EventInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, { event }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
event.hostId = hostId;
|
||||
const newEvent = new Event(event);
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
newEvent.save((err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(newEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
createEvent: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,21 +1,20 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { FormulaType } from '../types';
|
||||
import { Formula } from '../../models';
|
||||
import { FormulaInputType } from '../types/input';
|
||||
|
||||
const args = {
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
formula: { type: FormulaInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, { name }, context) => {
|
||||
const ownerId = context.userId;
|
||||
const resolve = (parent, { formula }, { userId: ownerId }) => {
|
||||
if (!ownerId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
const newFormula = new Formula({ name, ownerId });
|
||||
|
||||
formula.ownerId = ownerId;
|
||||
const newFormula = new Formula(formula);
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
newFormula.save((err) => {
|
||||
if (err) {
|
||||
|
||||
@@ -1,28 +1,20 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { PlotterType } from '../types';
|
||||
import { Plotter } from '../../models';
|
||||
import { PlotterInputType } from '../types/input';
|
||||
|
||||
const args = {
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
host: { type: new GraphQLNonNull(GraphQLString) },
|
||||
repo: { type: new GraphQLNonNull(GraphQLString) },
|
||||
moduleName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
plotter: { type: PlotterInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
name, host, repo, moduleName,
|
||||
}, context) => {
|
||||
const ownerId = context.userId;
|
||||
const resolve = (parent, { plotter }, { userId: ownerId }) => {
|
||||
if (!ownerId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
const newPlotter = new Plotter({
|
||||
name, host, repo, moduleName, ownerId,
|
||||
});
|
||||
|
||||
plotter.ownerId = ownerId;
|
||||
const newPlotter = new Plotter(plotter);
|
||||
|
||||
return new Promise((res, reject) => {
|
||||
newPlotter.save((err) => {
|
||||
if (err) {
|
||||
|
||||
@@ -1,54 +1,29 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLInt,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError } from '../../errors';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { EventInputType } from '../types/input';
|
||||
|
||||
const args = {
|
||||
designator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
name: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
startDatetime: { type: GraphQLInt },
|
||||
finishDatetime: { type: GraphQLInt },
|
||||
formulaId: { type: GraphQLString },
|
||||
plotterId: { type: GraphQLString },
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
event: { type: EventInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
designator, name, description, startDatetime, finishDatetime, formulaId, plotterId,
|
||||
}, context) => {
|
||||
const hostId = context.userId;
|
||||
const resolve = (parent, { eventId: _id, event }, { userId: hostId }) => {
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator, hostId }).exec((err, event) => {
|
||||
Event.findOneAndUpdate({ _id, hostId }, event, { new: true }, (err, modifiedEvent) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
event.name = name || event.name;
|
||||
event.description = description || event.description;
|
||||
event.startDatetime = startDatetime || event.startDatetime;
|
||||
event.finishDatetime = finishDatetime || event.finishDatetime;
|
||||
event.formula = formulaId || event.formula;
|
||||
event.plotter = plotterId || event.plotter;
|
||||
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
res(modifiedEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
@@ -11,45 +10,40 @@ import {
|
||||
} from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { ParticipantInputType } from '../types/input';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
teamId: { type: new GraphQLNonNull(GraphQLString) },
|
||||
botId: { type: GraphQLString },
|
||||
releaseId: { type: GraphQLString },
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
participant: { type: ParticipantInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
eventDesignator, teamId, botId, releaseId,
|
||||
}, context) => {
|
||||
const userid = context.userId;
|
||||
if (!userid) {
|
||||
const resolve = (parent,
|
||||
{ eventId: _id, participant: { teamId, botId, releaseId } },
|
||||
{ userId, authorization }) => {
|
||||
if (!userId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
axios({
|
||||
url: process.env.TEAMS_ENDPOINT,
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
{
|
||||
teamsByRole{
|
||||
teams_TeamsByRole{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
headers: {
|
||||
userid,
|
||||
authorization: context.authorization,
|
||||
},
|
||||
headers: { authorization },
|
||||
}).then(
|
||||
(result) => {
|
||||
if (!result.data.data.teamsByRole.some(team => team.id === teamId)) {
|
||||
rej(new WrongArgumentsError('You are not eligible to register this team'));
|
||||
rej(new WrongArgumentsError('You are not eligible to edit this team'));
|
||||
return;
|
||||
}
|
||||
Event.findOne({ designator: eventDesignator }).exec((err, event) => {
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLInt,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
rank: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
amount: { type: GraphQLInt },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventDesignator, rank, amount }, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
const prizeIndex = event.prizes.findIndex(prize => prize.rank === rank);
|
||||
if (!prizeIndex) {
|
||||
rej(new DatabaseError('There is no prize for that index'));
|
||||
return;
|
||||
}
|
||||
event.prizes[prizeIndex].amount = amount || event.prizes[prizeIndex].amount;
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
editPrize: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,64 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError, WrongArgumentsError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
title: { type: new GraphQLNonNull(GraphQLString) },
|
||||
newtitle: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
eventDesignator, title, newtitle, description,
|
||||
}, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
const ruleIndex = event.rules.findIndex(rule => rule.title === title);
|
||||
if (!ruleIndex) {
|
||||
rej(new DatabaseError('There is no rule with that title'));
|
||||
return;
|
||||
}
|
||||
event.rules[ruleIndex].description = description || event.rules[ruleIndex].description;
|
||||
if (event.rules.some(rule => rule.title === newtitle)) {
|
||||
rej(new WrongArgumentsError('There is already a rule using your new title'));
|
||||
return;
|
||||
}
|
||||
event.rules[ruleIndex].title = newtitle || event.rules[ruleIndex].title;
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
editRule: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -1,52 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLInt,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError } from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { slugify } from '../../utils/functions';
|
||||
|
||||
const args = {
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: new GraphQLNonNull(GraphQLString) },
|
||||
startDatetime: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
finishDatetime: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
name, description, startDatetime, finishDatetime,
|
||||
}, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
const newEvent = new Event({
|
||||
hostId,
|
||||
name,
|
||||
description,
|
||||
startDatetime,
|
||||
finishDatetime,
|
||||
});
|
||||
newEvent.designator = `${slugify(newEvent.name)}-${newEvent._id}`;
|
||||
return new Promise((res, rej) => {
|
||||
newEvent.save((err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res(newEvent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
hostEvent: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -2,7 +2,6 @@ import 'dotenv/config';
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLString,
|
||||
} from 'graphql';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
@@ -12,45 +11,40 @@ import {
|
||||
} from '../../errors';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { ParticipantInputType } from '../types/input';
|
||||
|
||||
const args = {
|
||||
designator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
teamId: { type: new GraphQLNonNull(GraphQLString) },
|
||||
botId: { type: GraphQLString },
|
||||
releaseId: { type: GraphQLString },
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
participant: { type: ParticipantInputType },
|
||||
};
|
||||
|
||||
const resolve = (parent, {
|
||||
designator, teamId, botId, releaseId,
|
||||
}, context) => {
|
||||
const userid = context.userId;
|
||||
if (!userid) {
|
||||
const resolve = (parent,
|
||||
{ eventId: _id, participant: { teamId, botId, releaseId } },
|
||||
{ userId, authorization }) => {
|
||||
if (!userId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
axios({
|
||||
url: process.env.TEAMS_ENDPOINT,
|
||||
url: process.env.GATEWAY_ENDPOINT,
|
||||
method: 'post',
|
||||
data: {
|
||||
query: `
|
||||
{
|
||||
teamsByRole{
|
||||
teams_TeamsByRole{
|
||||
id
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
headers: {
|
||||
userid,
|
||||
authorization: context.authorization,
|
||||
},
|
||||
headers: { authorization },
|
||||
}).then(
|
||||
(result) => {
|
||||
if (!result.data.data.teamsByRole.some(team => team.id === teamId)) {
|
||||
rej(new WrongArgumentsError('You are not eligible to register this team'));
|
||||
return;
|
||||
}
|
||||
Event.findOne({ designator }).exec((err, event) => {
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLInt,
|
||||
} from 'graphql';
|
||||
import { AuthentificationError, DatabaseError } from '../../errors';
|
||||
import { isBetween } from '../../utils/functions';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
fromPosition: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
toPosition: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
};
|
||||
|
||||
const resolve = (parent, { eventDesignator, fromPosition, toPosition }, context) => {
|
||||
const hostId = context.userId;
|
||||
if (!hostId) {
|
||||
throw new AuthentificationError();
|
||||
}
|
||||
return new Promise((res, rej) => {
|
||||
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events you own respond to that designator'));
|
||||
return;
|
||||
}
|
||||
const delta = fromPosition > toPosition ? 1 : -1;
|
||||
event.rules.forEach((part) => {
|
||||
if (part.position === fromPosition) {
|
||||
part.position = toPosition;
|
||||
} else if (isBetween(part.position, fromPosition, toPosition)) {
|
||||
part.position += delta;
|
||||
}
|
||||
});
|
||||
|
||||
event.save((error) => {
|
||||
if (error) {
|
||||
rej(error);
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const mutation = {
|
||||
reorderRules: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve,
|
||||
},
|
||||
};
|
||||
|
||||
export default mutation;
|
||||
@@ -2,36 +2,24 @@ import {
|
||||
GraphQLObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
import HostEventMutation from './HostEvent';
|
||||
import CreateEventMutation from './CreateEvent';
|
||||
import EditEventMutation from './EditEvent';
|
||||
import RegisterToEventMutation from './RegisterToEvent';
|
||||
import EditParticipantMutation from './EditParticipant';
|
||||
import AddRuleMutation from './AddRule';
|
||||
import EditRuleMutation from './EditRule';
|
||||
import ReorderRulesMutation from './ReorderRules';
|
||||
import AddPrizeMutation from './AddPrize';
|
||||
import EditPrizeMutation from './EditPrize';
|
||||
import CreateFormulaMutation from './CreateFormula';
|
||||
import CreateAndSetFormulaMutation from './CreateAndSetFormula';
|
||||
import CreatePlotterMutation from './CreatePlotter';
|
||||
import CreateAndSetPlotterMutation from './CreateAndSetPlotter';
|
||||
import ChangeEventStateMutation from './ChangeEventState';
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: Object.assign(
|
||||
HostEventMutation,
|
||||
CreateEventMutation,
|
||||
EditEventMutation,
|
||||
RegisterToEventMutation,
|
||||
EditParticipantMutation,
|
||||
AddRuleMutation,
|
||||
EditRuleMutation,
|
||||
ReorderRulesMutation,
|
||||
AddPrizeMutation,
|
||||
EditPrizeMutation,
|
||||
CreateFormulaMutation,
|
||||
CreateAndSetFormulaMutation,
|
||||
CreatePlotterMutation,
|
||||
CreateAndSetPlotterMutation,
|
||||
ChangeEventStateMutation,
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
|
||||
const args = {
|
||||
designator: { type: new GraphQLNonNull(GraphQLID) },
|
||||
eventId: { type: new GraphQLNonNull(GraphQLID) },
|
||||
};
|
||||
|
||||
const resolve = (parent, { designator }) => new Promise((res, rej) => {
|
||||
Event.findOne({ designator }).exec((err, event) => {
|
||||
const resolve = (parent, { eventId: _id }) => new Promise((res, rej) => {
|
||||
Event.findOne({ _id }).exec((err, event) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
if (!event) {
|
||||
rej(new DatabaseError('None of the events respond to that designator'));
|
||||
rej(new DatabaseError('None of the events respond to that id'));
|
||||
return;
|
||||
}
|
||||
res(event);
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
} from 'graphql';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
|
||||
|
||||
const args = {
|
||||
minDate: { type: GraphQLInt },
|
||||
@@ -12,6 +13,7 @@ const args = {
|
||||
|
||||
const resolve = (parent, { minDate, maxDate }) => Event.find(
|
||||
Object.assign(
|
||||
{ state: { $nin: [UNPUBLISHED, ARCHIVED] } },
|
||||
minDate || maxDate
|
||||
? {
|
||||
startDatetime:
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from 'graphql';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
|
||||
|
||||
const args = {
|
||||
hostId: { type: GraphQLString },
|
||||
@@ -14,7 +15,7 @@ const args = {
|
||||
|
||||
const resolve = (parent, { hostId, minDate, maxDate }, context) => Event.find(
|
||||
Object.assign(
|
||||
hostId ? { hostId } : { hostId: context.userId },
|
||||
hostId ? { hostId, state: { $nin: [UNPUBLISHED, ARCHIVED] } } : { hostId: context.userId },
|
||||
minDate || maxDate
|
||||
? {
|
||||
startDatetime:
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from 'graphql';
|
||||
import { EventType } from '../types';
|
||||
import { Event } from '../../models';
|
||||
import { UNPUBLISHED, ARCHIVED } from '../../enums/EventState';
|
||||
|
||||
const args = {
|
||||
teamId: { type: new GraphQLNonNull(GraphQLString) },
|
||||
@@ -15,7 +16,11 @@ const args = {
|
||||
|
||||
const resolve = (parent, { teamId, minDate, maxDate }) => Event.find(
|
||||
Object.assign(
|
||||
{ participants: { $elemMatch: { teamId } } },
|
||||
{
|
||||
participants: { $elemMatch: { teamId } },
|
||||
state: { $nin: [UNPUBLISHED, ARCHIVED] },
|
||||
},
|
||||
|
||||
minDate || maxDate
|
||||
? {
|
||||
startDatetime:
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInt,
|
||||
} from 'graphql';
|
||||
|
||||
const AdditionalPrizeType = new GraphQLObjectType({
|
||||
name: 'OtherPrize',
|
||||
name: 'AdditionalPrize',
|
||||
description: 'Non algo complementary prize',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
amount: { type: GraphQLInt },
|
||||
asset: { type: GraphQLString },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
asset: { type: new GraphQLNonNull(GraphQLString) },
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -12,11 +12,14 @@ import {
|
||||
ParticipantType,
|
||||
PrizeType,
|
||||
} from './index';
|
||||
import EventStateEnumType from './enum/EventState';
|
||||
|
||||
const EventType = new GraphQLObjectType({
|
||||
name: 'Event',
|
||||
description: 'Everything you need to know about an event',
|
||||
fields: () => ({
|
||||
designator: { type: GraphQLID },
|
||||
id: { type: GraphQLID },
|
||||
state: { type: EventStateEnumType },
|
||||
name: { type: GraphQLString },
|
||||
hostId: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
@@ -25,13 +28,13 @@ const EventType = new GraphQLObjectType({
|
||||
formula: {
|
||||
type: FormulaType,
|
||||
resolve(parent) {
|
||||
return parent.formula;
|
||||
return parent.formulaId;
|
||||
},
|
||||
},
|
||||
plotter: {
|
||||
type: PlotterType,
|
||||
resolve(parent) {
|
||||
return parent.plotter;
|
||||
return parent.plotterId;
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
|
||||
const FormulaType = new GraphQLObjectType({
|
||||
name: 'Formula',
|
||||
description: 'For now it\'s simplay a named field',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLString },
|
||||
ownerId: { type: GraphQLString },
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
|
||||
const ParticipantType = new GraphQLObjectType({
|
||||
name: 'Participant',
|
||||
description: 'Informations about the participant of an event',
|
||||
fields: () => ({
|
||||
teamId: { type: GraphQLString },
|
||||
botId: { type: GraphQLString },
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
|
||||
const PlotterType = new GraphQLObjectType({
|
||||
name: 'Plotter',
|
||||
description: 'Will soon change in order to use contained plotter objects',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLString },
|
||||
ownerId: { type: GraphQLString },
|
||||
|
||||
@@ -2,14 +2,16 @@ import {
|
||||
GraphQLObjectType,
|
||||
GraphQLList,
|
||||
GraphQLInt,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
import { AdditionalPrizeType } from './index';
|
||||
|
||||
const PrizeType = new GraphQLObjectType({
|
||||
name: 'Prize',
|
||||
description: 'Prize, by default in algos',
|
||||
fields: () => ({
|
||||
rank: { type: GraphQLInt },
|
||||
amount: { type: GraphQLInt },
|
||||
rank: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
additional: {
|
||||
type: new GraphQLList(AdditionalPrizeType),
|
||||
resolve(parent) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
|
||||
const RuleType = new GraphQLObjectType({
|
||||
name: 'Rule',
|
||||
description: 'Textual rules of an event',
|
||||
fields: () => ({
|
||||
position: { type: GraphQLInt },
|
||||
title: { type: GraphQLString },
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
GraphQLEnumType,
|
||||
} from 'graphql';
|
||||
|
||||
import { EventStateEnum } from '../../../enums/EventState';
|
||||
|
||||
const values = {};
|
||||
EventStateEnum.forEach((EventState) => {
|
||||
values[EventState] = { value: EventState };
|
||||
});
|
||||
|
||||
const EventStateEnumType = new GraphQLEnumType({
|
||||
name: 'EventStateEnum',
|
||||
values,
|
||||
});
|
||||
|
||||
export {
|
||||
EventStateEnumType as default,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInt,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'AdditionalPrizeInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
asset: { type: new GraphQLNonNull(GraphQLString) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
GraphQLString,
|
||||
GraphQLInt,
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
} from 'graphql';
|
||||
import InputPrizeType from './Prize';
|
||||
import InputRuleType from './Rule';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'EventInput',
|
||||
description: 'Payload for event input',
|
||||
fields: () => ({
|
||||
name: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
startDatetime: { type: GraphQLInt },
|
||||
finishDatetime: { type: GraphQLInt },
|
||||
formulaId: { type: GraphQLString },
|
||||
plotterId: { type: GraphQLString },
|
||||
prizes: { type: new GraphQLList(InputPrizeType) },
|
||||
rules: { type: new GraphQLList(InputRuleType) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'FormulaInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLString,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'ParticipantInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
teamId: { type: new GraphQLNonNull(GraphQLString) },
|
||||
botId: { type: GraphQLString },
|
||||
releaseId: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'PlotterInput',
|
||||
description: 'Payload for plotter input',
|
||||
fields: () => ({
|
||||
name: { type: new GraphQLNonNull(GraphQLString) },
|
||||
host: { type: GraphQLString },
|
||||
repo: { type: GraphQLString },
|
||||
moduleName: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
GraphQLInputObjectType,
|
||||
GraphQLList,
|
||||
GraphQLInt,
|
||||
GraphQLNonNull,
|
||||
} from 'graphql';
|
||||
import InputAdditionalPrizeType from './AdditionalPrize';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'PrizeInput',
|
||||
description: 'Payload for formula input',
|
||||
fields: () => ({
|
||||
rank: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
amount: { type: new GraphQLNonNull(GraphQLInt) },
|
||||
additional: {
|
||||
type: new GraphQLList(InputAdditionalPrizeType),
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLString,
|
||||
GraphQLInt,
|
||||
GraphQLInputObjectType,
|
||||
} from 'graphql';
|
||||
|
||||
const Type = new GraphQLInputObjectType({
|
||||
name: 'RuleInput',
|
||||
description: 'Payload for rule input',
|
||||
fields: () => ({
|
||||
position: { type: GraphQLInt },
|
||||
title: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: GraphQLString },
|
||||
}),
|
||||
});
|
||||
|
||||
export default Type;
|
||||
@@ -0,0 +1,17 @@
|
||||
import PlotterInputType from './Plotter';
|
||||
import RuleInputType from './Rule';
|
||||
import PrizeInputType from './Prize';
|
||||
import FormulaInputType from './Formula';
|
||||
import EventInputType from './Event';
|
||||
import AdditionalPrizeInputType from './AdditionalPrize';
|
||||
import ParticipantInputType from './Participant';
|
||||
|
||||
export {
|
||||
PlotterInputType,
|
||||
RuleInputType,
|
||||
PrizeInputType,
|
||||
FormulaInputType,
|
||||
EventInputType,
|
||||
AdditionalPrizeInputType,
|
||||
ParticipantInputType,
|
||||
};
|
||||
Reference in new issue
Block a user