went from standardjs to eslinter with airbnb settings(untested)
This commit is contained in:
1 parent
4550d06224
commit
657c8a1a9b
41 files changed
+2257
-817
No files matched your search
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
};
|
||||
Reference in new issue
Block a user