Add objective group mutation
This commit is contained in:
parent
8d9cb86ae8
commit
a1fd28b48e
|
|
@ -0,0 +1,16 @@
|
||||||
|
#import "../fragments/objectiveGroupParts.gql"
|
||||||
|
mutation AddObjectiveGroup($input: AddObjectiveGroupInput!) {
|
||||||
|
addObjectiveGroup(input: $input) {
|
||||||
|
objectiveGroup {
|
||||||
|
...ObjectiveGroupParts
|
||||||
|
objectives {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import graphene
|
||||||
|
from graphene import InputObjectType
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectiveInput(InputObjectType):
|
||||||
|
text = graphene.String(required=True)
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectiveGroupInput(InputObjectType):
|
||||||
|
title = graphene.String(required=True)
|
||||||
|
module = graphene.ID(required=True)
|
||||||
|
objectives = graphene.List(ObjectiveInput)
|
||||||
|
|
||||||
|
|
||||||
|
class AddObjectiveGroupArgument(ObjectiveGroupInput):
|
||||||
|
pass
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import graphene
|
import graphene
|
||||||
from graphene import relay, InputObjectType
|
from graphene import relay, InputObjectType
|
||||||
from api.utils import get_object
|
from api.utils import get_object
|
||||||
|
from books.models import Module
|
||||||
from books.schema.inputs import UserGroupBlockVisibility
|
from books.schema.inputs import UserGroupBlockVisibility
|
||||||
from core.utils import set_visible_for, set_hidden_for
|
from core.utils import set_visible_for, set_hidden_for
|
||||||
|
from objectives.inputs import AddObjectiveGroupArgument
|
||||||
from objectives.models import ObjectiveProgressStatus, Objective, ObjectiveGroup
|
from objectives.models import ObjectiveProgressStatus, Objective, ObjectiveGroup
|
||||||
from objectives.schema import ObjectiveNode, ObjectiveGroupNode
|
from objectives.schema import ObjectiveNode, ObjectiveGroupNode
|
||||||
|
|
||||||
|
|
@ -52,10 +54,32 @@ class UpdateObjectiveGroupVisibility(relay.ClientIDMutation):
|
||||||
|
|
||||||
objective_group.save()
|
objective_group.save()
|
||||||
|
|
||||||
|
|
||||||
return cls(objective_group=objective_group)
|
return cls(objective_group=objective_group)
|
||||||
|
|
||||||
|
|
||||||
|
class AddObjectiveGroup(relay.ClientIDMutation):
|
||||||
|
class Input:
|
||||||
|
objective_group = graphene.Argument(AddObjectiveGroupArgument)
|
||||||
|
|
||||||
|
objective_group = graphene.Field(ObjectiveGroupNode)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
|
objective_group_data = kwargs.get('objective_group')
|
||||||
|
title = objective_group_data.get('title')
|
||||||
|
if title != 'society':
|
||||||
|
title = 'language_communication'
|
||||||
|
module_id = objective_group_data.get('module')
|
||||||
|
module = get_object(Module, module_id)
|
||||||
|
owner = info.context.user
|
||||||
|
new_objective_group = ObjectiveGroup.objects.create(title=title, module=module, owner=owner)
|
||||||
|
objectives = objective_group_data.get('objectives')
|
||||||
|
for objective in objectives:
|
||||||
|
Objective.objects.create(text=objective.get('text'), group=new_objective_group)
|
||||||
|
return cls(objective_group=new_objective_group)
|
||||||
|
|
||||||
|
|
||||||
class ObjectiveMutations:
|
class ObjectiveMutations:
|
||||||
update_objective_progress = UpdateObjectiveProgress.Field()
|
update_objective_progress = UpdateObjectiveProgress.Field()
|
||||||
update_objective_group_visibility = UpdateObjectiveGroupVisibility.Field()
|
update_objective_group_visibility = UpdateObjectiveGroupVisibility.Field()
|
||||||
|
add_objective_group = AddObjectiveGroup.Field()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue