Function create_user_notification

Source
pub async fn create_user_notification(
    pool: &Pool<MySql>,
    user_id: i64,
    message: &str,
    notification_type: &str,
    org_id: Option<i64>,
    app_id: Option<i64>,
    importance: Option<&str>,
    action_url: Option<&str>,
    action_label: Option<&str>,
    expires_at: Option<DateTime<Utc>>,
) -> Result<UserNotification>
Expand description

Creates a new notification for a user.

This function inserts a new user notification record with the provided parameters. It handles both required fields and optional fields.

§Arguments

  • pool - Database connection pool for executing the query
  • user_id - ID of the user to notify
  • message - The notification message text
  • notification_type - Type of notification (info, warning, error, success)
  • org_id - Optional organization ID related to the notification
  • app_id - Optional application ID related to the notification
  • importance - Optional importance level (default is “normal”)
  • action_url - Optional URL for a related action
  • action_label - Optional label for the action button
  • expires_at - Optional expiration date for the notification

§Returns

  • Ok(UserNotification) - Successfully created notification, including database-assigned fields
  • Err(anyhow::Error) - Failed to create notification