Exemple #1
0
    def mutate(self, info, **kwargs):
        validate_empty_fields(**kwargs)
        rating_values = ["Excellent", "Very Good", "Good", "Average", "Poor"]
        ratings = ["comments", "overall_rating", "cleanliness_rating"]

        query = Room.get_query(info)
        room = query.filter_by(id=kwargs['room_id']).first()
        if not room:
            raise GraphQLError("Non-existent room id")

        if not set(ratings).intersection(kwargs):
            raise GraphQLError("Ensure to give at least one feedback input")
        ratings.pop(0)

        for feedback in kwargs:
            if feedback in ratings:
                if kwargs[feedback] not in rating_values:
                    raise GraphQLError("Invalid rating, only " +
                                       ', '.join(rating_values) +
                                       " ratings allowed")  # noqa

        user = get_user_from_db()
        feedback = FeedbackModel(**kwargs, user_id=user.id)
        feedback.save()
        return CreateFeedback(feedback=feedback)
Exemple #2
0
    def __init__(self, **kwargs):
        validate_empty_fields(**kwargs)

        self.name = kwargs['name']
        self.device_type = kwargs['device_type']
        self.date_added = kwargs['date_added']
        self.last_seen = kwargs['last_seen']
        self.location = kwargs['location']
        self.resource_id = kwargs['resource_id']
Exemple #3
0
 def mutate(self, info, wing_id, **kwargs):
     validate_empty_fields(**kwargs)
     get_wing = Wing.get_query(info)
     exact_wing = get_wing.filter(WingModel.id == wing_id).first()
     if not exact_wing:
         raise GraphQLError("Wing not found")
     admin_roles.create_update_delete_wing()
     update_entity_fields(exact_wing, **kwargs)
     with SaveContextManager(exact_wing, kwargs['name'], 'Wing'):
         return UpdateWing(wing=exact_wing)
Exemple #4
0
 def mutate(self, info, **kwargs):
     validate_empty_fields(**kwargs)
     floor = Floor.query.filter_by(id=kwargs['floor_id']).first()
     if not floor:
         raise GraphQLError("Floor not found")
     admin_roles.check_office_location_create_wing(floor_id=kwargs['floor_id'])  # noqa: E501
     admin_roles.create_update_delete_wing()
     wing = WingModel(**kwargs)
     with SaveContextManager(wing, kwargs['name'], 'Wing'):
         return CreateWing(wing=wing)
Exemple #5
0
    def mutate(self, info, room_id, **kwargs):
        validate_empty_fields(**kwargs)
        query_room = Room.get_query(info)
        exact_room = query_room.filter(RoomModel.id == room_id).first()
        if not exact_room:
            raise GraphQLError("Room not found")

        admin_roles.update_delete_rooms_create_resource(room_id)
        update_entity_fields(exact_room, **kwargs)

        exact_room.save()
        return UpdateRoom(room=exact_room)
Exemple #6
0
    def mutate(self, info, block_id, **kwargs):
        validate_empty_fields(**kwargs)
        query = Block.get_query(info)
        exact_block = query.filter(BlockModel.id == block_id).first()
        if not exact_block:
            raise GraphQLError("Block not found")

        admin_roles.update_delete_block(block_id)

        update_entity_fields(exact_block, **kwargs)
        exact_block.save()
        return UpdateBlock(block=exact_block)
Exemple #7
0
    def mutate(self, info, resource_id, **kwargs):
        validate_empty_fields(**kwargs)
        query = Resource.get_query(info)
        exact_resource = query.filter(ResourceModel.id == resource_id).first()
        if not exact_resource:
            raise GraphQLError("Resource not found")

        admin_roles.update_resource(resource_id, room_id=kwargs['room_id'])

        update_entity_fields(exact_resource, **kwargs)
        exact_resource.save()
        return UpdateRoomResource(resource=exact_resource)
Exemple #8
0
    def mutate(self, info, office_id, **kwargs):
        validate_empty_fields(**kwargs)
        get_office = Office.get_query(info)
        exact_office = get_office.filter(OfficeModel.id == office_id).first()
        if not exact_office:
            raise GraphQLError("Office not found")
        admin_roles.create_rooms_update_delete_office(office_id)
        try:
            update_entity_fields(exact_office, **kwargs)
            exact_office.save()
        except exc.SQLAlchemyError:
            raise GraphQLError("Action Failed")

        return UpdateOffice(office=exact_office)
Exemple #9
0
    def mutate(self, info, device_id, **kwargs):
        validate_empty_fields(**kwargs)

        query_device = Devices.get_query(info)
        exact_device = query_device.filter(
            DevicesModel.id == device_id).first()
        if not exact_device:
            raise GraphQLError("DeviceId not found")
        exact_device.date_added = datetime.now()
        exact_device.last_seen = datetime.now()
        update_entity_fields(exact_device, **kwargs)

        exact_device.save()
        return UpdateDevice(device=exact_device)
Exemple #10
0
 def mutate(self, info, location_id, **kwargs):
     location = Location.get_query(info)
     location_object = location.filter(
         LocationModel.id == location_id).first()
     if not location_object:
         raise GraphQLError("Location not found")
     if "time_zone" in kwargs:
         validate_timezone_field(**kwargs)
     if "country" in kwargs:
         validate_country_field(**kwargs)
     if "name" in kwargs or "abbreviation" in kwargs or "imageUrl" in kwargs:  # noqa
         validate_empty_fields(**kwargs)
     update_entity_fields(location_object, **kwargs)
     location_object.save()
     return UpdateLocation(location=location_object)
Exemple #11
0
 def mutate(self, info, **kwargs):
     validate_empty_fields(**kwargs)
     block_name = BlockModel.query.filter_by(
         name=kwargs['name'].title()).all()  # noqa
     if block_name:
         raise GraphQLError("Block aleady exists")
     get_office = Office.query.filter_by(id=kwargs['office_id']).first()
     if not get_office:
         raise GraphQLError("Office not found")
     location = get_office.location.name
     if location.lower() == 'nairobi':
         block = BlockModel(**kwargs)
         block.save()
     else:
         raise GraphQLError("You can only create block in Nairobi")
     return CreateBlock(block=block)
Exemple #12
0
    def mutate(self, info, floor_id, **kwargs):
        validate_empty_fields(**kwargs)
        query_floor = Floor.get_query(info)
        exact_floor = query_floor.filter(FloorModel.id == floor_id).first()
        if not exact_floor:
            raise GraphQLError("Floor not found")

        admin_roles.update_delete_floor(floor_id)
        result = query_floor.filter(
            FloorModel.block_id == exact_floor.block_id,
            FloorModel.name == kwargs.get('name').capitalize())
        if result.count() > 0:
            ErrorHandler.check_conflict(self, kwargs['name'], 'Floor')

        update_entity_fields(exact_floor, **kwargs)
        exact_floor.save()
        return UpdateFloor(floor=exact_floor)
Exemple #13
0
    def mutate(self, info, **kwargs):
        validate_empty_fields(**kwargs)
        get_block = Block.query.filter_by(id=kwargs['block_id']).first()
        if not get_block:
            raise GraphQLError("Block not found")
        query = Floor.get_query(info)
        query_block = query.join(Block.floors)

        admin_roles.create_floor(kwargs['block_id'])
        result = query_block.filter(
            Block.id == kwargs['block_id'],
            FloorModel.name == kwargs.get('name').capitalize())
        if result.count() > 0:
            ErrorHandler.check_conflict(self, kwargs['name'], 'Floor')

        floor = FloorModel(**kwargs)
        floor.save()
        return CreateFloor(floor=floor)
Exemple #14
0
    def __init__(self, **kwargs):
        validate_empty_fields(**kwargs)

        self.name = kwargs.get('name')
        self.quantity = kwargs.get('quantity')
        self.room_id = kwargs.get('room_id')
Exemple #15
0
    def __init__(self, **kwargs):

        validate_empty_fields(**kwargs)

        self.role = kwargs['role']
Exemple #16
0
    def __init__(self, **kwargs):

        validate_empty_fields(**kwargs)

        self.user_id = kwargs['user_id']
        self.role_id = kwargs['role_id']
Exemple #17
0
    def __init__(self, **kwargs):
        validate_empty_fields(**kwargs)

        self.email = kwargs['email']
        self.name = kwargs['name']
        self.picture = kwargs['picture']