refactoring resolve functions out of query core
This commit is contained in:
1 parent
758368161b
commit
a51cf97127
4 files changed
+72
-64
No files matched your search
@@ -15,31 +15,33 @@ const args = {
|
||||
formula: { type: new GraphQLNonNull(GraphQLString) }
|
||||
}
|
||||
|
||||
const resolve = (parent, args, context) => {
|
||||
// let authIdOnSession = context.user.sub
|
||||
let authIdOnSession = 'some-id'
|
||||
let newCompetition = new Competition({
|
||||
host: authIdOnSession,
|
||||
displayName: args.displayName,
|
||||
description: args.description,
|
||||
startDatetime: args.startDatetime,
|
||||
finishDatetime: args.finishDatetime,
|
||||
formula: args.formula
|
||||
})
|
||||
newCompetition.codeName = slugify(newCompetition.displayName) + '-' + newCompetition._id
|
||||
return new Promise((resolve, reject) => {
|
||||
newCompetition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(newCompetition)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
hostCompetition: {
|
||||
type: CompetitionType,
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
// let authIdOnSession = context.user.sub
|
||||
let authIdOnSession = 'some-id'
|
||||
let newCompetition = new Competition({
|
||||
host: authIdOnSession,
|
||||
displayName: args.displayName,
|
||||
description: args.description,
|
||||
startDatetime: args.startDatetime,
|
||||
finishDatetime: args.finishDatetime,
|
||||
formula: args.formula
|
||||
})
|
||||
newCompetition.codeName = slugify(newCompetition.displayName) + '-' + newCompetition._id
|
||||
return new Promise((resolve, reject) => {
|
||||
newCompetition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(newCompetition)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,36 +13,38 @@ const args = {
|
||||
release: { type: new GraphQLNonNull(GraphQLString) }
|
||||
}
|
||||
|
||||
const resolve = (parent, args, context) => {
|
||||
// let authIdOnSession = context.user.sub
|
||||
return new Promise((resolve, reject) => {
|
||||
Competition.findOne({ codeName: args.codeName }).exec((err, competition) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
if (competition.participants.some(participant => participant.devTeam === args.devTeam)) {
|
||||
// need to add an error message here TODO
|
||||
resolve(competition)
|
||||
} else {
|
||||
competition.participants.push({
|
||||
devTeam: args.devTeam,
|
||||
bot: args.bot,
|
||||
release: args.release
|
||||
})
|
||||
competition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(competition)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
registerToCompetition: {
|
||||
type: CompetitionType,
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
// let authIdOnSession = context.user.sub
|
||||
return new Promise((resolve, reject) => {
|
||||
Competition.findOne({ codeName: args.codeName }).exec((err, competition) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
if (competition.participants.some(participant => participant.devTeam === args.devTeam)) {
|
||||
// need to add an error message here TODO
|
||||
resolve(competition)
|
||||
} else {
|
||||
competition.participants.push({
|
||||
devTeam: args.devTeam,
|
||||
bot: args.bot,
|
||||
release: args.release
|
||||
})
|
||||
competition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(competition)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,17 +10,19 @@ const args = {
|
||||
includeOld: { type: GraphQLBoolean }
|
||||
}
|
||||
|
||||
const resolve = (parent, args, context) => {
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
))
|
||||
}
|
||||
|
||||
const query = {
|
||||
competitions: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
))
|
||||
}
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,20 +13,22 @@ const args = {
|
||||
includeOld: { type: GraphQLBoolean }
|
||||
}
|
||||
|
||||
const resolve = (parent, args, context) => {
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{
|
||||
host: args.host
|
||||
},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
const query = {
|
||||
competitionsByHost: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args,
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find(
|
||||
Object.assign(
|
||||
{
|
||||
host: args.host
|
||||
},
|
||||
args.includeOld ? { finishDatetime: { $gt: epoch() } } : {}
|
||||
)
|
||||
)
|
||||
}
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user