Merge pull request #13 from nikolabjelo/master

Cleaning up the backend
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2018-11-01 08:13:30 +01:00
commit 548b275968
43 files changed
+2329 -823

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
module.exports = {
parser: 'babel-eslint',
extends: 'airbnb-base',
rules: {
'no-underscore-dangle': 'off',
'no-param-reassign': 'off'
}
};
+1423 -25
View File
File diff suppressed because it is too large. Load diff
+4
View File
@@ -16,8 +16,12 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^10.0.1",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"nodemon": "^1.18.4"
},
"dependencies": {
+40
View File
@@ -0,0 +1,40 @@
import 'dotenv/config';
import express from 'express';
import cors from 'cors';
import graphqlHTTP from 'express-graphql';
import expressPlayground from 'graphql-playground-middleware-express';
import * as Sentry from '@sentry/node';
import schema from './schema';
const app = express();
// Initialising sentry
Sentry.init({ dsn: process.env.SENTRY_DNS });
app.use(Sentry.Handlers.requestHandler());
// authorising CORS
app.use(cors());
// Starting the graphql server
app.use('/graphql', graphqlHTTP(req => ({
schema,
context: {
userId: req.headers.userid,
authorization: req.headers.authorization,
},
formatError(err) {
return {
message: err.message,
code: err.originalError && err.originalError.code,
path: err.path,
};
},
})));
// Starting the graphql server
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
// Sentry error handling middleware if anything pass through
app.use(Sentry.Handlers.errorHandler());
export default app;
+9
View File
@@ -0,0 +1,9 @@
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.Promise = global.Promise;
const db = mongoose.connection;
export default db;
+17
View File
@@ -0,0 +1,17 @@
export const UNPUBLISHED = 'UNPUBLISHED';
export const PUBLISHED = 'PUBLISHED';
export const CANCELLED = 'CANCELLED';
export const RUNNING = 'RUNNING';
export const INTERRUPTED = 'INTERRUPTED';
export const FINISHED = 'FINISHED';
export const EventStatusEnum = [
UNPUBLISHED,
PUBLISHED,
CANCELLED,
RUNNING,
INTERRUPTED,
FINISHED,
];
export default EventStatusEnum;
+33 -7
View File
@@ -1,19 +1,45 @@
export class AuthentificationError extends Error {
import * as Sentry from '@sentry/node';
class ClientError extends Error {
constructor(args) {
super(args);
Sentry.configureScope((scope) => {
scope.setLevel('debug');
});
Sentry.captureException(this);
}
}
class ServerError extends Error {
constructor(args) {
super(args);
Sentry.configureScope((scope) => {
scope.setLevel('error');
});
Sentry.captureException(this);
}
}
export class AuthentificationError extends ClientError {
code = 401
message = 'Autentification not found, you have to be authentificated to perform this action'
}
export class DatabaseError extends Error {
export class DatabaseError extends ClientError {
code = 404
message = 'Ressource not found : ' + this.message
message = `Ressource not found : ${this.message}`
}
export class WrongArgumentsError extends Error {
export class WrongArgumentsError extends ClientError {
code = 400
message = 'Wrong arguments : ' + this.message
message = `Wrong arguments : ${this.message}`
}
export class ServiceUnavailableError extends Error {
export class ServiceUnavailableError extends ServerError {
code = 503
message = 'At least one service is unresponding ' + this.message
message = `At least one service is unresponding ${this.message}`
}
+19 -52
View File
@@ -1,55 +1,22 @@
import express from 'express'
import 'dotenv/config'
import cors from 'cors'
import mongoose from 'mongoose'
import graphqlHTTP from 'express-graphql'
import expressPlayground from 'graphql-playground-middleware-express'
/* eslint-disable no-console */
import * as Sentry from '@sentry/node';
import db from './db';
import app from './app';
import schema from './schema'
import * as Sentry from '@sentry/node'
// Initialise express
const app = express()
// Initialising sentry
Sentry.init({ dsn: process.env.SENTRY_DNS })
app.use(Sentry.Handlers.requestHandler())
// Allow cross origing request
app.use(cors())
/* -------------------------------------------------
---------------- Database setup --------------------
------------------------------------------------- */
// Database Connection
mongoose.connect(`mongodb://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${process.env.DB_DOMAIN}`, { useNewUrlParser: true })
// Get Mongoose to use the global promise library
mongoose.Promise = global.Promise
// Get the default connection
var db = mongoose.connection
// bind error and success to console log
db.on('error', () => { console.error.bind(console, 'MongoDB connection error:') })
db.once('open', () => { console.log('Connected to the DB.') })
/* -------------------------------------------------
----------------- Graphql setup --------------------
------------------------------------------------- */
app.use('/graphql', graphqlHTTP(req => {
return {
schema: schema,
context: {
userId: req.headers.userid,
authorization: req.headers.authorization
}
}
}))
app.get('/playground', expressPlayground({ endpoint: '/graphql' }))
// Sentry error handling middleware
app.use(Sentry.Handlers.errorHandler())
// Bind server success and error to sentry
db.on('error', (err) => {
Sentry.configureScope((scope) => {
scope.setLevel('error');
});
Sentry.captureException(err);
});
db.once('open', () => {
Sentry.configureScope((scope) => {
scope.setLevel('info');
});
Sentry.captureMessage('Connected to the DB.');
});
app.listen(process.env.PORT, () => {
console.log(`Listening on port ${process.env.PORT}`)
})
console.log(`Listening on port ${process.env.PORT}`);
});
+24 -19
View File
@@ -1,9 +1,14 @@
import mongoose, { Schema } from 'mongoose'
import Plotter from './plotter'
import Formula from './formula'
import mongoose, { Schema } from 'mongoose';
import Plotter from './plotter';
import Formula from './formula';
import {
UNPUBLISHED,
EventStatusEnum,
} from '../enums/EventStatus';
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,
@@ -14,7 +19,7 @@ const eventSchema = new Schema({
rules: [{
position: { type: Number, required: true },
title: { type: String, required: true },
description: String
description: String,
}],
prizes: [{
rank: { type: Number, required: true },
@@ -22,25 +27,25 @@ const eventSchema = new Schema({
additional: [{
condition: String,
amount: { type: Number, required: true },
asset: { type: String, required: true }
}]
asset: { type: String, required: true },
}],
}],
participants: [{
teamId: { type: String, required: true },
botId: String,
releaseId: String
}]
})
releaseId: String,
}],
});
eventSchema.pre('find', function () {
this.populate('formula').populate('plotter')
})
eventSchema.post('save', function (doc, next) {
doc.populate('formula').populate('plotter').execPopulate().then(function () {
next()
})
})
eventSchema.pre('find', function populate() {
this.populate('formula').populate('plotter');
});
eventSchema.post('save', (doc, next) => {
doc.populate('formula').populate('plotter').execPopulate().then(() => {
next();
});
});
const Event = mongoose.model('Event', eventSchema)
const Event = mongoose.model('Event', eventSchema);
export default Event
export default Event;
+5 -5
View File
@@ -1,11 +1,11 @@
import mongoose, { Schema } from 'mongoose'
import mongoose, { Schema } from 'mongoose';
const formulaSchema = new Schema({
ownerId: { type: String, required: true },
isTemplate: { type: Boolean, default: false },
name: { type: String, required: true }
})
name: { type: String, required: true },
});
const Formula = mongoose.model('Formula', formulaSchema)
const Formula = mongoose.model('Formula', formulaSchema);
export default Formula
export default Formula;
+5 -5
View File
@@ -1,9 +1,9 @@
import Plotter from './plotter'
import Event from './event'
import Formula from './formula'
import Plotter from './plotter';
import Event from './event';
import Formula from './formula';
export {
Event,
Plotter,
Formula
}
Formula,
};
+5 -5
View File
@@ -1,4 +1,4 @@
import mongoose, { Schema } from 'mongoose'
import mongoose, { Schema } from 'mongoose';
const plotterSchema = new Schema({
ownerId: { type: String, required: true },
@@ -6,9 +6,9 @@ const plotterSchema = new Schema({
name: { type: String, required: true },
host: { type: String, required: true },
repo: { type: String, required: true },
moduleName: { type: String, required: true }
})
moduleName: { type: String, required: true },
});
const Plotter = mongoose.model('Plotter', plotterSchema)
const Plotter = mongoose.model('Plotter', plotterSchema);
export default Plotter
export default Plotter;
+7 -7
View File
@@ -1,13 +1,13 @@
import {
GraphQLSchema
} from 'graphql'
GraphQLSchema,
} from 'graphql';
import Mutation from './mutations'
import RootQuery from './queries'
import Mutation from './mutations';
import RootQuery from './queries';
const Schema = new GraphQLSchema({
query: RootQuery,
mutation: Mutation
})
mutation: Mutation,
});
export default Schema
export default Schema;
+39 -36
View File
@@ -1,59 +1,62 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLInt
} from 'graphql'
GraphQLInt,
} from 'graphql';
import {
AuthentificationError,
DatabaseError,
WrongArgumentsError
} from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
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) }
}
amount: { type: new GraphQLNonNull(GraphQLInt) },
};
const resolve = (parent, { eventDesignator, rank, amount }, context) => {
const hostId = context.userId
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
if (event.prizes.some(prize => prize.rank === rank)) {
reject(new WrongArgumentsError('A prize for that rank already exists'))
} else {
event.prizes.push({
rank,
amount
})
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
}
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
}
}
resolve,
},
};
export default mutation
export default mutation;
+47 -41
View File
@@ -1,64 +1,70 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql'
GraphQLString,
} from 'graphql';
import {
AuthentificationError,
DatabaseError,
WrongArgumentsError
} from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
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) }
}
description: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { eventDesignator, title, description }, context) => {
const hostId = context.userId
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
if (event.rules.some(rule => rule.title === title)) {
reject(new WrongArgumentsError('A prize for that rank already exists'))
} else {
let position = 1
while (event.rules.some(rule => rule.position === position)) {
position++
}
event.rules.push({
position,
title,
description
})
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
}
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
}
}
resolve,
},
};
export default mutation
export default mutation;
@@ -1,52 +1,56 @@
import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError, DatabaseError } from '../../errors'
import { EventType } from '../types'
import { Event, Formula } from '../../models'
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) }
}
name: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { name, eventDesignator }, context) => {
const ownerId = context.userId
const ownerId = context.userId;
if (!ownerId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
let newFormula = new Formula({ name, ownerId })
return new Promise((resolve, reject) => {
const newFormula = new Formula({ name, ownerId });
return new Promise((res, reject) => {
Event.findOne({ designator: eventDesignator, hostId: ownerId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
newFormula.save((err) => {
if (err) reject(err)
else {
}
})
event.formula = newFormula._id
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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
}
}
resolve,
},
};
export default mutation
export default mutation;
@@ -1,55 +1,65 @@
import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError, DatabaseError } from '../../errors'
import { EventType } from '../types'
import { Event, Plotter } from '../../models'
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) }
}
moduleName: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { name, host, repo, moduleName, eventDesignator }, context) => {
const ownerId = context.userId
const resolve = (parent, {
name, host, repo, moduleName, eventDesignator,
}, context) => {
const ownerId = context.userId;
if (!ownerId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
let newPlotter = new Plotter({ name, host, repo, moduleName, ownerId })
return new Promise((resolve, reject) => {
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) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
newPlotter.save((err) => {
if (err) reject(err)
else {
}
})
event.plotter = newPlotter._id
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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
}
}
resolve,
},
};
export default mutation
export default mutation;
+22 -21
View File
@@ -1,37 +1,38 @@
import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { FormulaType } from '../types'
import { Formula } from '../../models'
GraphQLString,
} from 'graphql';
import { AuthentificationError } from '../../errors';
import { FormulaType } from '../types';
import { Formula } from '../../models';
const args = {
name: { type: new GraphQLNonNull(GraphQLString) }
}
name: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { name }, context) => {
const ownerId = context.userId
const ownerId = context.userId;
if (!ownerId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
let newFormula = new Formula({ name, ownerId })
return new Promise((resolve, reject) => {
const newFormula = new Formula({ name, ownerId });
return new Promise((res, rej) => {
newFormula.save((err) => {
if (err) reject(err)
else {
resolve(newFormula)
if (err) {
rej(err);
return;
}
})
})
}
res(newFormula);
});
});
};
const mutation = {
createFormula: {
type: FormulaType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+27 -22
View File
@@ -1,40 +1,45 @@
import {
GraphQLNonNull,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { PlotterType } from '../types'
import { Plotter } from '../../models'
GraphQLString,
} from 'graphql';
import { AuthentificationError } from '../../errors';
import { PlotterType } from '../types';
import { Plotter } from '../../models';
const args = {
name: { type: new GraphQLNonNull(GraphQLString) },
host: { type: new GraphQLNonNull(GraphQLString) },
repo: { type: new GraphQLNonNull(GraphQLString) },
moduleName: { type: new GraphQLNonNull(GraphQLString) }
}
moduleName: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { name, host, repo, moduleName }, context) => {
const ownerId = context.userId
const resolve = (parent, {
name, host, repo, moduleName,
}, context) => {
const ownerId = context.userId;
if (!ownerId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
let newPlotter = new Plotter({ name, host, repo, moduleName, ownerId })
return new Promise((resolve, reject) => {
const newPlotter = new Plotter({
name, host, repo, moduleName, ownerId,
});
return new Promise((res, reject) => {
newPlotter.save((err) => {
if (err) reject(err)
else {
resolve(newPlotter)
if (err) {
reject(err);
return;
}
})
})
}
res(newPlotter);
});
});
};
const mutation = {
createPlotter: {
type: PlotterType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+40 -35
View File
@@ -2,11 +2,11 @@ import {
GraphQLNonNull,
GraphQLID,
GraphQLInt,
GraphQLString
} from 'graphql'
import { AuthentificationError, DatabaseError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
GraphQLString,
} from 'graphql';
import { AuthentificationError, DatabaseError } from '../../errors';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
designator: { type: new GraphQLNonNull(GraphQLID) },
@@ -15,45 +15,50 @@ const args = {
startDatetime: { type: GraphQLInt },
finishDatetime: { type: GraphQLInt },
formulaId: { type: GraphQLString },
plotterId: { type: GraphQLString }
}
plotterId: { type: GraphQLString },
};
const resolve = (parent, { designator, name, description, startDatetime, finishDatetime, formulaId, plotterId }, context) => {
const hostId = context.userId
const resolve = (parent, {
designator, name, description, startDatetime, finishDatetime, formulaId, plotterId,
}, context) => {
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator, hostId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
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((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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);
});
});
});
};
const mutation = {
editEvent: {
type: EventType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+48 -46
View File
@@ -1,30 +1,32 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql'
import axios from 'axios'
GraphQLString,
} from 'graphql';
import axios from 'axios';
import {
AuthentificationError,
WrongArgumentsError,
ServiceUnavailableError
} from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
ServiceUnavailableError,
} from '../../errors';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
eventDesignator: { type: new GraphQLNonNull(GraphQLID) },
teamId: { type: new GraphQLNonNull(GraphQLString) },
botId: { type: GraphQLString },
releaseId: { type: GraphQLString }
}
releaseId: { type: GraphQLString },
};
const resolve = (parent, { eventDesignator, teamId, botId, releaseId }, context) => {
const userid = context.userId
const resolve = (parent, {
eventDesignator, teamId, botId, releaseId,
}, context) => {
const userid = context.userId;
if (!userid) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
axios({
url: process.env.TEAMS_ENDPOINT,
method: 'post',
@@ -35,53 +37,53 @@ const resolve = (parent, { eventDesignator, teamId, botId, releaseId }, context)
id
}
}
`
`,
},
headers: {
userid,
authorization: context.authorization
}
authorization: context.authorization,
},
}).then(
(result) => {
if (!result.data.data.teamsByRole.some(team => team.id === teamId)) {
reject(new WrongArgumentsError('You are not eligible to register this team'))
return
rej(new WrongArgumentsError('You are not eligible to register this team'));
return;
}
Event.findOne({ designator: eventDesignator }).exec((err, event) => {
if (err) reject(err)
else {
let participantIndex
event.participants.find((participant, index) => {
if (participant.teamId === teamId) {
participantIndex = index
}
})
event.participants[participantIndex].botId = botId || event.participants[participantIndex].botId
event.participants[participantIndex].releaseId = releaseId || event.participants[participantIndex].releaseId
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
if (err) {
rej(err);
return;
}
})
const participantIndex = event.participant
.findIndex(participant => participant.teamId === teamId);
event.participants[participantIndex].botId = botId
|| event.participants[participantIndex].botId;
event.participants[participantIndex].releaseId = releaseId
|| event.participants[participantIndex].releaseId;
event.save((error) => {
if (error) {
rej(error);
return;
}
res(event);
});
});
},
(error) => {
reject(new ServiceUnavailableError(error))
}
)
})
}
rej(new ServiceUnavailableError(error));
},
);
});
};
const mutation = {
editParticipant: {
type: EventType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+36 -38
View File
@@ -1,58 +1,56 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLInt
} from 'graphql'
import { AuthentificationError, DatabaseError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
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 }
}
amount: { type: GraphQLInt },
};
const resolve = (parent, { eventDesignator, rank, amount }, context) => {
const hostId = context.userId
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
let prizeIndex = null
event.prizes.find((prize, index) => {
if (prize.rank === rank) {
prizeIndex = index
}
})
if (!prizeIndex) {
reject(new DatabaseError('There is no prize for that index'))
return
}
event.prizes[prizeIndex].amount = amount || event.prizes[prizeIndex].amount
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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
}
}
resolve,
},
};
export default mutation
export default mutation;
+44 -45
View File
@@ -1,65 +1,64 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql'
import { AuthentificationError, DatabaseError, WrongArgumentsError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
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 }
}
description: { type: GraphQLString },
};
const resolve = (parent, { eventDesignator, title, newtitle, description }, context) => {
const hostId = context.userId
const resolve = (parent, {
eventDesignator, title, newtitle, description,
}, context) => {
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator: eventDesignator, hostId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
let ruleIndex = null
event.rules.find((rule, index) => {
if (rule.title === title) {
ruleIndex = index
}
})
if (!ruleIndex) {
reject(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)) {
reject(new WrongArgumentsError('There is already a rule using your new title'))
} else {
event.rules[ruleIndex].title = newtitle || event.rules[ruleIndex].title
}
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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
}
}
resolve,
},
};
export default mutation
export default mutation;
+29 -26
View File
@@ -1,49 +1,52 @@
import {
GraphQLNonNull,
GraphQLInt,
GraphQLString
} from 'graphql'
import { AuthentificationError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
import { slugify } from '../../utils/functions'
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) }
}
finishDatetime: { type: new GraphQLNonNull(GraphQLInt) },
};
const resolve = (parent, { name, description, startDatetime, finishDatetime }, context) => {
const hostId = context.userId
const resolve = (parent, {
name, description, startDatetime, finishDatetime,
}, context) => {
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
let newEvent = new Event({
const newEvent = new Event({
hostId,
name,
description,
startDatetime,
finishDatetime
})
newEvent.designator = slugify(newEvent.name) + '-' + newEvent._id
return new Promise((resolve, reject) => {
finishDatetime,
});
newEvent.designator = `${slugify(newEvent.name)}-${newEvent._id}`;
return new Promise((res, rej) => {
newEvent.save((err) => {
if (err) reject(err)
else {
resolve(newEvent)
if (err) {
rej(err);
return;
}
})
})
}
res(newEvent);
});
});
};
const mutation = {
hostEvent: {
type: EventType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+50 -46
View File
@@ -1,31 +1,33 @@
import 'dotenv/config'
import 'dotenv/config';
import {
GraphQLNonNull,
GraphQLID,
GraphQLString
} from 'graphql'
import axios from 'axios'
GraphQLString,
} from 'graphql';
import axios from 'axios';
import {
AuthentificationError,
WrongArgumentsError,
ServiceUnavailableError
} from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
ServiceUnavailableError,
} from '../../errors';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
designator: { type: new GraphQLNonNull(GraphQLID) },
teamId: { type: new GraphQLNonNull(GraphQLString) },
botId: { type: GraphQLString },
releaseId: { type: GraphQLString }
}
releaseId: { type: GraphQLString },
};
const resolve = (parent, { designator, teamId, botId, releaseId }, context) => {
const userid = context.userId
const resolve = (parent, {
designator, teamId, botId, releaseId,
}, context) => {
const userid = context.userId;
if (!userid) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
axios({
url: process.env.TEAMS_ENDPOINT,
method: 'post',
@@ -36,52 +38,54 @@ const resolve = (parent, { designator, teamId, botId, releaseId }, context) => {
id
}
}
`
`,
},
headers: {
userid,
authorization: context.authorization
}
authorization: context.authorization,
},
}).then(
(result) => {
if (!result.data.data.teamsByRole.some(team => team.id === teamId)) {
reject(new WrongArgumentsError('You are not eligible to register this team'))
return
rej(new WrongArgumentsError('You are not eligible to register this team'));
return;
}
Event.findOne({ designator }).exec((err, event) => {
if (err) reject(err)
else {
if (event.participants.some(participant => participant.teamId === teamId)) {
reject(new WrongArgumentsError('You are already registred'))
} else {
event.participants.push({
teamId,
botId,
releaseId
})
event.save((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
}
if (err) {
rej(err);
return;
}
})
if (event.participants.some(participant => participant.teamId === teamId)) {
rej(new WrongArgumentsError('You are already registred'));
return;
}
event.participants.push({
teamId,
botId,
releaseId,
});
event.save((error) => {
if (error) {
rej(error);
return;
}
res(event);
});
});
},
(error) => {
reject(new ServiceUnavailableError(error))
}
)
})
}
rej(new ServiceUnavailableError(error));
},
);
});
};
const mutation = {
registerToEvent: {
type: EventType,
args,
resolve
}
}
resolve,
},
};
export default mutation
export default mutation;
+40 -37
View File
@@ -1,57 +1,60 @@
import {
GraphQLNonNull,
GraphQLID,
GraphQLInt
} from 'graphql'
import { AuthentificationError, DatabaseError } from '../../errors'
import { isBetween } from '../../utils/functions'
import { EventType } from '../types'
import { Event } from '../../models'
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) }
}
toPosition: { type: new GraphQLNonNull(GraphQLInt) },
};
const resolve = (parent, { eventDesignator, fromPosition, toPosition }, context) => {
const hostId = context.userId
const hostId = context.userId;
if (!hostId) {
throw new AuthentificationError()
throw new AuthentificationError();
}
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
Event.findOne({ designator: eventDesignator, hostId: context.userId }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events you own respond to that designator'))
} else {
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((err) => {
if (err) reject(err)
else {
resolve(event)
}
})
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
}
}
resolve,
},
};
export default mutation
export default mutation;
+19 -19
View File
@@ -1,20 +1,20 @@
import {
GraphQLObjectType
} from 'graphql'
GraphQLObjectType,
} from 'graphql';
import HostEventMutation from './HostEvent'
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 HostEventMutation from './HostEvent';
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';
const Mutation = new GraphQLObjectType({
name: 'Mutation',
@@ -31,8 +31,8 @@ const Mutation = new GraphQLObjectType({
CreateFormulaMutation,
CreateAndSetFormulaMutation,
CreatePlotterMutation,
CreateAndSetPlotterMutation
)
})
CreateAndSetPlotterMutation,
),
});
export default Mutation
export default Mutation;
+24 -24
View File
@@ -1,35 +1,35 @@
import {
GraphQLNonNull,
GraphQLID
} from 'graphql'
import { DatabaseError } from '../../errors'
import { EventType } from '../types'
import { Event } from '../../models'
GraphQLID,
} from 'graphql';
import { DatabaseError } from '../../errors';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
designator: { type: new GraphQLNonNull(GraphQLID) }
}
designator: { type: new GraphQLNonNull(GraphQLID) },
};
const resolve = (parent, { designator }, context) => {
return new Promise((resolve, reject) => {
Event.findOne({ designator }).exec((err, event) => {
if (err) {
reject(err)
} else if (!event) {
reject(new DatabaseError('None of the events respond to that designator'))
} else {
resolve(event)
}
})
})
}
const resolve = (parent, { designator }) => new Promise((res, rej) => {
Event.findOne({ designator }).exec((err, event) => {
if (err) {
rej(err);
return;
}
if (!event) {
rej(new DatabaseError('None of the events respond to that designator'));
return;
}
res(event);
});
});
const query = {
event: {
type: EventType,
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+21 -21
View File
@@ -1,35 +1,35 @@
import {
GraphQLInt,
GraphQLList
} from 'graphql'
import { EventType } from '../types'
import { Event } from '../../models'
GraphQLList,
} from 'graphql';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
minDate: { type: GraphQLInt },
maxDate: { type: GraphQLInt }
}
maxDate: { type: GraphQLInt },
};
const resolve = (parent, { minDate, maxDate }, context) => {
return Event.find(
Object.assign(
minDate || maxDate
? { startDatetime:
const resolve = (parent, { minDate, maxDate }) => Event.find(
Object.assign(
minDate || maxDate
? {
startDatetime:
Object.assign(
minDate ? { $gte: minDate } : {},
maxDate ? { $lte: maxDate } : {}
) }
: {}
)
)
}
maxDate ? { $lte: maxDate } : {},
),
}
: {},
),
);
const query = {
events: {
type: new GraphQLList(EventType),
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+22 -22
View File
@@ -1,38 +1,38 @@
import {
GraphQLInt,
GraphQLList,
GraphQLString
} from 'graphql'
import { EventType } from '../types'
import { Event } from '../../models'
GraphQLString,
} from 'graphql';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
hostId: { type: GraphQLString },
minDate: { type: GraphQLInt },
maxDate: { type: GraphQLInt }
}
maxDate: { type: GraphQLInt },
};
const resolve = (parent, { hostId, minDate, maxDate }, context) => {
return Event.find(
Object.assign(
hostId ? { hostId } : { hostId: context.userId },
minDate || maxDate
? { startDatetime:
const resolve = (parent, { hostId, minDate, maxDate }, context) => Event.find(
Object.assign(
hostId ? { hostId } : { hostId: context.userId },
minDate || maxDate
? {
startDatetime:
Object.assign(
minDate ? { $gte: minDate } : {},
maxDate ? { $lte: maxDate } : {}
) }
: {}
)
)
}
maxDate ? { $lte: maxDate } : {},
),
}
: {},
),
);
const query = {
eventsByHost: {
type: new GraphQLList(EventType),
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+22 -22
View File
@@ -2,38 +2,38 @@ import {
GraphQLInt,
GraphQLList,
GraphQLString,
GraphQLNonNull
} from 'graphql'
import { EventType } from '../types'
import { Event } from '../../models'
GraphQLNonNull,
} from 'graphql';
import { EventType } from '../types';
import { Event } from '../../models';
const args = {
teamId: { type: new GraphQLNonNull(GraphQLString) },
minDate: { type: GraphQLInt },
maxDate: { type: GraphQLInt }
}
maxDate: { type: GraphQLInt },
};
const resolve = (parent, { teamId, minDate, maxDate }, context) => {
return Event.find(
Object.assign(
{ participants: { $elemMatch: { teamId } } },
minDate || maxDate
? { startDatetime:
const resolve = (parent, { teamId, minDate, maxDate }) => Event.find(
Object.assign(
{ participants: { $elemMatch: { teamId } } },
minDate || maxDate
? {
startDatetime:
Object.assign(
minDate ? { $gte: minDate } : {},
maxDate ? { $lte: maxDate } : {}
) }
: {}
)
)
}
maxDate ? { $lte: maxDate } : {},
),
}
: {},
),
);
const query = {
eventsByTeam: {
type: new GraphQLList(EventType),
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+10 -12
View File
@@ -1,21 +1,19 @@
import {
GraphQLList
} from 'graphql'
import { FormulaType } from '../types'
import { Formula } from '../../models'
GraphQLList,
} from 'graphql';
import { FormulaType } from '../types';
import { Formula } from '../../models';
const args = {}
const args = {};
const resolve = (parent, args, context) => {
return Formula.find()
}
const resolve = () => Formula.find();
const query = {
formulas: {
type: new GraphQLList(FormulaType),
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+10 -12
View File
@@ -1,21 +1,19 @@
import {
GraphQLList
} from 'graphql'
import { PlotterType } from '../types'
import { Plotter } from '../../models'
GraphQLList,
} from 'graphql';
import { PlotterType } from '../types';
import { Plotter } from '../../models';
const args = {}
const args = {};
const resolve = (parent, args, context) => {
return Plotter.find()
}
const resolve = () => Plotter.find();
const query = {
plotters: {
type: new GraphQLList(PlotterType),
args,
resolve
}
}
resolve,
},
};
export default query
export default query;
+12 -12
View File
@@ -1,13 +1,13 @@
import {
GraphQLObjectType
} from 'graphql'
GraphQLObjectType,
} from 'graphql';
import EventQuery from './Event'
import EventsQuery from './Events'
import EventsByHostQuery from './EventsByHost'
import EventsByTeamQuery from './EventsByTeam'
import FormulasQuery from './Formulas'
import PlottersQuery from './Plotters'
import EventQuery from './Event';
import EventsQuery from './Events';
import EventsByHostQuery from './EventsByHost';
import EventsByTeamQuery from './EventsByTeam';
import FormulasQuery from './Formulas';
import PlottersQuery from './Plotters';
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
@@ -17,8 +17,8 @@ const RootQuery = new GraphQLObjectType({
EventsByHostQuery,
EventsByTeamQuery,
FormulasQuery,
PlottersQuery
)
})
PlottersQuery,
),
});
export default RootQuery
export default RootQuery;
+6 -6
View File
@@ -1,16 +1,16 @@
import {
GraphQLObjectType,
GraphQLString,
GraphQLInt
} from 'graphql'
GraphQLInt,
} from 'graphql';
const AdditionalPrizeType = new GraphQLObjectType({
name: 'OtherPrize',
fields: () => ({
condition: { type: GraphQLString },
amount: { type: GraphQLInt },
asset: { type: GraphQLString }
})
})
asset: { type: GraphQLString },
}),
});
export default AdditionalPrizeType
export default AdditionalPrizeType;
+23 -23
View File
@@ -3,15 +3,15 @@ import {
GraphQLInt,
GraphQLString,
GraphQLList,
GraphQLID
} from 'graphql'
GraphQLID,
} from 'graphql';
import {
FormulaType,
PlotterType,
RuleType,
ParticipantType,
PrizeType
} from './index'
PrizeType,
} from './index';
const EventType = new GraphQLObjectType({
name: 'Event',
@@ -24,35 +24,35 @@ const EventType = new GraphQLObjectType({
finishDatetime: { type: GraphQLInt },
formula: {
type: FormulaType,
resolve (parent, args) {
return parent.formula
}
resolve(parent) {
return parent.formula;
},
},
plotter: {
type: PlotterType,
resolve (parent, args) {
return parent.plotter
}
resolve(parent) {
return parent.plotter;
},
},
rules: {
type: new GraphQLList(RuleType),
resolve (parent, args) {
return parent.rules
}
resolve(parent) {
return parent.rules;
},
},
participants: {
type: new GraphQLList(ParticipantType),
resolve (parent, args) {
return parent.participants
}
resolve(parent) {
return parent.participants;
},
},
prizes: {
type: new GraphQLList(PrizeType),
resolve (parent, args) {
return parent.prizes
}
}
})
})
resolve(parent) {
return parent.prizes;
},
},
}),
});
export default EventType
export default EventType;
+6 -6
View File
@@ -1,8 +1,8 @@
import {
GraphQLObjectType,
GraphQLString,
GraphQLBoolean
} from 'graphql'
GraphQLBoolean,
} from 'graphql';
const FormulaType = new GraphQLObjectType({
name: 'Formula',
@@ -10,8 +10,8 @@ const FormulaType = new GraphQLObjectType({
id: { type: GraphQLString },
ownerId: { type: GraphQLString },
isTemplate: { type: GraphQLBoolean },
name: { type: GraphQLString }
})
})
name: { type: GraphQLString },
}),
});
export default FormulaType
export default FormulaType;
+6 -6
View File
@@ -1,15 +1,15 @@
import {
GraphQLObjectType,
GraphQLString
} from 'graphql'
GraphQLString,
} from 'graphql';
const ParticipantType = new GraphQLObjectType({
name: 'Participant',
fields: () => ({
teamId: { type: GraphQLString },
botId: { type: GraphQLString },
releaseId: { type: GraphQLString }
})
})
releaseId: { type: GraphQLString },
}),
});
export default ParticipantType
export default ParticipantType;
+6 -6
View File
@@ -1,8 +1,8 @@
import {
GraphQLObjectType,
GraphQLString,
GraphQLBoolean
} from 'graphql'
GraphQLBoolean,
} from 'graphql';
const PlotterType = new GraphQLObjectType({
name: 'Plotter',
@@ -13,8 +13,8 @@ const PlotterType = new GraphQLObjectType({
name: { type: GraphQLString },
host: { type: GraphQLString },
repo: { type: GraphQLString },
moduleName: { type: GraphQLString }
})
})
moduleName: { type: GraphQLString },
}),
});
export default PlotterType
export default PlotterType;
+10 -10
View File
@@ -1,9 +1,9 @@
import {
GraphQLObjectType,
GraphQLList,
GraphQLInt
} from 'graphql'
import { AdditionalPrizeType } from './index'
GraphQLInt,
} from 'graphql';
import { AdditionalPrizeType } from './index';
const PrizeType = new GraphQLObjectType({
name: 'Prize',
@@ -12,11 +12,11 @@ const PrizeType = new GraphQLObjectType({
amount: { type: GraphQLInt },
additional: {
type: new GraphQLList(AdditionalPrizeType),
resolve (parent, args) {
return parent.additional
}
}
})
})
resolve(parent) {
return parent.additional;
},
},
}),
});
export default PrizeType
export default PrizeType;
+6 -6
View File
@@ -1,16 +1,16 @@
import {
GraphQLObjectType,
GraphQLInt,
GraphQLString
} from 'graphql'
GraphQLString,
} from 'graphql';
const RuleType = new GraphQLObjectType({
name: 'Rule',
fields: () => ({
position: { type: GraphQLInt },
title: { type: GraphQLString },
description: { type: GraphQLString }
})
})
description: { type: GraphQLString },
}),
});
export default RuleType
export default RuleType;
+9 -9
View File
@@ -1,10 +1,10 @@
import PlotterType from './Plotter'
import RuleType from './Rule'
import ParticipantType from './Participant'
import AdditionalPrizeType from './AdditionalPrize'
import PrizeType from './Prize'
import FormulaType from './Formula'
import EventType from './Event'
import PlotterType from './Plotter';
import RuleType from './Rule';
import ParticipantType from './Participant';
import AdditionalPrizeType from './AdditionalPrize';
import PrizeType from './Prize';
import FormulaType from './Formula';
import EventType from './Event';
export {
PlotterType,
@@ -13,5 +13,5 @@ export {
AdditionalPrizeType,
PrizeType,
FormulaType,
EventType
}
EventType,
};
+13 -20
View File
@@ -1,26 +1,19 @@
export const capitalize = (string) => {
return (string).charAt(0).toUpperCase() + (string).slice(1)
}
export const capitalize = string => (string).charAt(0).toUpperCase() + (string).slice(1);
export const slugify = (text) => {
return text.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '')
}
export const slugify = text => text.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '')
.replace(/--+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
export const epoch = () => {
return Math.round(new Date().getTime() / 1000)
}
export const epoch = () => Math.round(new Date().getTime() / 1000);
export const isBetween = (value, valA, valB) => {
const min = valA < valB ? valA : valB
const max = valA > valB ? valA : valB
const min = valA < valB ? valA : valB;
const max = valA > valB ? valA : valB;
if (value >= min && value <= max) {
return true
} else {
return false
return true;
}
}
return false;
};