def update_prompt_in_db()

in web-backend/backendUtils/db.py [0:0]


def update_prompt_in_db(prompt_data: dict):
    """
    Update a prompt document in the prompts container.
    Assumes the document's 'id' is present in prompt_data and that
    the partition key is the same as the prompt's id.
    """
    try:
        # Read the existing item first (optional, but useful for etag handling)
        existing_item = prompts_container.read_item(
            item=prompt_data['id'],
            partition_key=prompt_data['id']
        )
        # Replace the item with the updated data
        updated_item = prompts_container.replace_item(
            item=existing_item,
            body=prompt_data
        )
        logging.info(f"Prompt updated: {prompt_data['id']}")
        return updated_item
    except exceptions.CosmosHttpResponseError as e:
        logging.error(f"Error updating prompt {prompt_data.get('id')}: {str(e)}")
        return None