def update_leave_days_by_id(id, body):  # noqa: E501
    """Updates a LeaveDays in the system with form data. Role write:leave_days must be granted

     # noqa: E501

    :param id: ID of LeaveDays to return
    :type id: int
    :param body: LeaveDays object that needs to be updated in the system
    :type body: dict | bytes

    :rtype: LeaveDays
    """
    found = dao.get(id)
    if found is None:
        return ErrorApiResponse.LeaveDaysNotFoundError(id=id), 404
    if connexion.request.is_json:
        body = LeaveDays.from_dict(connexion.request.get_json())  # noqa: E501
    delta = body.end_date - body.start_date
    if delta.days < 0:
        return ErrorApiResponse.LeaveDaysPeriodError(body.start_date,
                                                     body.end_date), 409
    # check already exists
    duplicate = find_leave_days_by(body.employee_id, body.start_date,
                                   body.end_date)
    if len(duplicate) > 1 or (len(duplicate) == 1 and duplicate[0].id != id):
        return ErrorApiResponse.LeaveDaysExistError(body.employee_id,
                                                    body.start_date,
                                                    body.end_date), 409
    # check employee exist
    employee = employee_dao.get(body.employee_id)
    if employee is None:
        return ErrorApiResponse.EmployeeNotFoundError(body.employee_id), 404
    # check rules
    conflict = rules.check_rules(body.employee_id, body.start_date,
                                 body.end_date, id)
    if len(conflict) > 0:
        return ApiResponseConflict(code=5000,
                                   type='leave days',
                                   message='Restrictions are violated',
                                   details=conflict), 409
    found.employee_id = body.employee_id
    found.start_date = body.start_date
    found.end_date = body.end_date
    found.leave_days = body.leave_days
    try:
        dao.persist(found)
        return get_leave_days_by_id(id)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='leave days'), 500
def add_leave_days(body):  # noqa: E501
    """Add a employee LeaveDays to the system. Role write:leave_days must be granted

     # noqa: E501

    :param body: LeaveDays object that needs to be added to the system
    :type body: dict | bytes

    :rtype: LeaveDays
    """
    if connexion.request.is_json:
        body = LeaveDays.from_dict(connexion.request.get_json())  # noqa: E501
    delta = body.end_date - body.start_date
    if delta.days < 0:
        return ErrorApiResponse.LeaveDaysPeriodError(body.start_date,
                                                     body.end_date), 409
    # check already exists
    found = dao.find_by(body.employee_id, body.start_date, body.end_date, None)
    if len(found) > 0:
        return ErrorApiResponse.LeaveDaysExistError(body.employee_id,
                                                    body.start_date,
                                                    body.end_date), 409
    # check employee exist
    found = employee_dao.get(body.employee_id)
    if found is None:
        return ErrorApiResponse.EmployeeNotFoundError(body.employee_id), 404

    # check rules FIXME
    conflict = rules.check_rules(body.employee_id, body.start_date,
                                 body.end_date)
    if len(conflict) > 0:
        return ApiResponseConflict(code=5000,
                                   type='leave days',
                                   message='Restrictions are violated',
                                   details=conflict), 409
    orm = LeaveDays_orm(employee_id=body.employee_id,
                        leave_days=body.leave_days,
                        start_date=body.start_date,
                        end_date=body.end_date)
    try:
        dao.persist(orm)
        return find_leave_days_by_date(body.employee_id, body.start_date)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex, type='leave days'), 500