Пример #1
0
 def mutate(self, info, location_id, **kwargs):
     query = Location.get_query(info)
     result = query.filter(LocationModel.state == "active")
     location = result.filter(
         LocationModel.id == location_id).first()  # noqa: E501
     if not location:
         raise GraphQLError("location not found")
     admin_roles.verify_admin_location(location_id)
     update_entity_fields(location, state="archived", **kwargs)
     location.save()
     return DeleteLocation(location=location)
Пример #2
0
 def mutate(self, info, **kwargs):
     location = Location.query.filter_by(id=kwargs['location_id']).first()
     if not location:
         raise GraphQLError("Location not found")
     admin_roles.verify_admin_location(location_id=kwargs['location_id'])
     office = OfficeModel(**kwargs)
     admin = get_user_from_db()
     email = admin.email
     username = email.split("@")[0]
     admin_name = username.split(".")[0]
     payload = {
         'model': OfficeModel, 'field': 'name', 'value':  kwargs['name']
         }
     with SaveContextManager(
        office, 'Office', payload
     ):
         new_office = kwargs['name']
         if not send_email_notification(email, new_office, location.name, admin_name):  # noqa
             raise GraphQLError("Office created but Emails not Sent")
         return CreateOffice(office=office)
Пример #3
0
 def mutate(self, info, location_id, **kwargs):
     location = Location.get_query(info)
     result = location.filter(LocationModel.state == "active")
     location_object = result.filter(
         LocationModel.id == location_id).first()
     if not location_object:
         raise GraphQLError("Location not found")
     admin_roles.verify_admin_location(location_id)
     if "time_zone" in kwargs:
         validate_timezone_field(**kwargs)
     if "country" in kwargs:
         validate_country_field(**kwargs)
     if "image_url" in kwargs:
         validate_url(**kwargs)
     validate_empty_fields(**kwargs)
     active_locations = result.filter(
         LocationModel.name == kwargs.get('name'))
     if active_locations:
         pass
     else:
         raise AttributeError("Not a valid location")
     update_entity_fields(location_object, **kwargs)
     location_object.save()
     return UpdateLocation(location=location_object)