Esempio n. 1
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to update a Student!")
     old_student = Student.objects.get(id=args.get('student').get("id"))
     try:
         tutor = Tutor.objects.get(
             id=args.get('student').get('tutor').get('id'))
     except:
         raise GraphQLError("Tutor with id {} does not exist".format(
             args.get('student').get('tutor_id')))
     try:
         god_parent = GodParent.objects.get(
             id=args.get('student').get('god_parent_id'))
     except:
         raise GraphQLError("GodParent with id {} does not exist".format(
             args.get('student').get('god_parent_id')))
     old_student.__dict__.update(args.get('student'))
     old_student.tutor = tutor
     old_student.god_parent = god_parent
     serializer = serializerEmployee(data=old_student,
                                     modelSerializer=StudentSerializer)
     if serializer.is_valid(raise_exception=True):
         old_student.save()
         return UpdateStudent(student=old_student)
Esempio n. 2
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to add a Tutor!")
     tutor = Tutor(**args.get('tutor'))
     serializer = serializerEmployee(data=tutor,
                                     modelSerializer=TutorSerializer)
     if serializer.is_valid(raise_exception=True):
         tutor.save()
         return CreateTutor(tutor=tutor)
Esempio n. 3
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to update a Tutor!")
     old_tutor = Tutor.objects.get(id=args.get('tutor_id'))
     old_tutor.__dict__.update(args.get('tutor'))
     serializer = serializerEmployee(data=old_tutor,
                                     modelSerializer=TutorSerializer)
     if serializer.is_valid(raise_exception=True):
         old_tutor.save()
         return UpdateTutor(tutor=old_tutor)
Esempio n. 4
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to add a Employee!")
     new_employee = Employee(**args.get('employee'))
     serializer = serializerEmployee(data=new_employee, modelSerializer=EmployeeSerializer)
     if serializer.is_valid(raise_exception=True):
         employees = Employee.objects.filter(email__icontains=new_employee.email)
         if len(list(employees)):
             raise EmailAlreadyExistException(new_employee.email)
         new_employee.save()
         return CreateEmployee(employee=new_employee)
Esempio n. 5
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to add a GodParent!")
     print(args.get('godparent'))
     godparent = GodParent(**args.get('godparent'))
     serializer = serializerEmployee(data=godparent, modelSerializer=GodParentSerializer)
     if serializer.is_valid(raise_exception=True):
         godparents = GodParent.objects.filter(email__icontains=godparent.email)
         if len(list(godparents)):
             raise EmailAlreadyExistException(godparent.email)
         godparent.save()
         return CreateGodParent(godparent=godparent)
Esempio n. 6
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to update an Employee!")
     old_employee = Employee.objects.get(id=args.get('employee_id'))
     email = old_employee.email
     old_employee.__dict__.update(args.get('employee'))
     serializer = serializerEmployee(data=old_employee, modelSerializer=EmployeeSerializer)
     if serializer.is_valid(raise_exception=True):
         employees = Employee.objects.filter(email__icontains=old_employee.email)
         if old_employee.email != email and len(list(employees)):
             raise EmailAlreadyExistException(old_employee.email)
         Employee.save(old_employee)
         return UpdateEmployee(employee=old_employee)
Esempio n. 7
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to update a GodParent!")
     print("-----------")
     print(args.get('godparent_id'))
     old_godparent = GodParent.objects.get(id=args.get('godparent_id'))
     print(old_godparent)
     print('------------')
     print(args.get('godparent'))
     old_godparent.__dict__.update(args.get('godparent'))
     email = old_godparent.email
     godparents = GodParent.objects.filter(email__icontains=old_godparent.email)
     serializer = serializerEmployee(data=old_godparent, modelSerializer=GodParentSerializer)
     if serializer.is_valid(raise_exception=True):
         if old_godparent.email != email and len(list(godparents)):
           raise EmailAlreadyExistException(old_godparent.email)
         old_godparent.save()
         return UpdateGodParent(godparent=old_godparent)
Esempio n. 8
0
 def mutate(self, info, **args):
     user = info.context.user
     if user.is_anonymous:
         raise GraphQLError("Log in to add a Student!")
     #TODO manage error handling
     try:
         tutor = Tutor.objects.get(id=args.get('student').get('tutor_id'))
     except:
         raise GraphQLError("Tutor with id {} does not exist".format(
             args.get('student').get('tutor_id')))
     try:
         god_parent = GodParent.objects.get(
             id=args.get('student').get('god_parent_id'))
     except:
         raise GraphQLError("GodParent with id {} does not exist".format(
             args.get('student').get('god_parent_id')))
     student = Student(tutor=tutor,
                       god_parent=god_parent,
                       **args.get('student'))
     serializer = serializerEmployee(data=student,
                                     modelSerializer=StudentSerializer)
     if serializer.is_valid(raise_exception=True):
         student.save()
         return CreateStudent(student=student)