Creating a "editParticipantOfCompetition" mutation
This commit is contained in:
1 parent
eacd89f8a7
commit
6e5932581c
2 files changed
+54
-1
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID,
|
||||
GraphQLString
|
||||
} from 'graphql'
|
||||
import { CompetitionType } from '../types'
|
||||
import Competition from '../../models/competition'
|
||||
|
||||
const args = {
|
||||
codeName: { type: new GraphQLNonNull(GraphQLID) },
|
||||
devTeam: { type: new GraphQLNonNull(GraphQLString) },
|
||||
bot: { type: GraphQLString },
|
||||
release: { type: GraphQLString }
|
||||
}
|
||||
|
||||
const resolve = (parent, { codeName, devTeam, bot, release }, context) => {
|
||||
// let authIdOnSession = context.user.sub
|
||||
return new Promise((resolve, reject) => {
|
||||
Competition.findOne({ codeName }).exec((err, competition) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
let participantIndex
|
||||
competition.participants.find((participant, index) => {
|
||||
if (participant.devTeam === devTeam) {
|
||||
participantIndex = index
|
||||
}
|
||||
})
|
||||
|
||||
competition.participants[participantIndex].bot = bot || competition.participants[participantIndex].bot
|
||||
competition.participants[participantIndex].release = release || competition.participants[participantIndex].release
|
||||
|
||||
competition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(competition)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const mutation = {
|
||||
editParticipantOfCompetition: {
|
||||
type: CompetitionType,
|
||||
args,
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
export default mutation
|
||||
@@ -7,6 +7,7 @@ import RegisterToCompetitionMutation from './RegisterToCompetition'
|
||||
import AddRuleToCompetitionMutation from './AddRuleToCompetition'
|
||||
import EditCompetitionMutation from './EditCompetition'
|
||||
import EditRuleOfCompetitionMutation from './EditRuleOfCompetition'
|
||||
import EditParticipantOfCompetitionMutation from './EditParticipantOfCompetition'
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
@@ -15,7 +16,8 @@ const Mutation = new GraphQLObjectType({
|
||||
RegisterToCompetitionMutation,
|
||||
AddRuleToCompetitionMutation,
|
||||
EditCompetitionMutation,
|
||||
EditRuleOfCompetitionMutation
|
||||
EditRuleOfCompetitionMutation,
|
||||
EditParticipantOfCompetitionMutation
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user