def update_task_category()

in project/paperbench/paperbench/gui/app.py [0:0]


def update_task_category():
    """Updates the task category for the given node_id."""
    with lock:
        data = sanitize_request_data(request.json)
        node_id = data.get("node_id")
        new_task_category = data.get("category")

        try:
            with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "r") as f:
                rubric = json.load(f)

            old_root = app.config["NODE_TYPE"].from_dict(rubric)
            old_node = old_root.find(node_id)
            new_node = old_node.set_task_category(new_task_category)
            new_root = old_root.replace(node_id, new_node)

            with open(app.config["PATH_TO_PAPER"] / app.config["RUBRIC_FILE_NAME"], "w") as f:
                json.dump(new_root.to_dict(), f, indent=4)

            return jsonify({"status": "success"})
        except Exception as e:
            return jsonify(
                {
                    "status": "error",
                    "message": f"Error updating task category for node {node_id}: {str(e)}",
                }
            )