Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

723 B
Raw Blame
use sqlx::{Pool, Postgres};

/// Gets all users that need to be notified for a document
/// This does not include the owner of the document
#[tracing::instrument(skip(db))]
pub async fn get_document_notification_users(
    db: &Pool<Postgres>,
    document_id: &str,
) -> anyhow::Result<Vec<String>> {
    let users = sqlx::query!(
        r#"
        SELECT
            u."id" as id
            FROM "Document" d
            INNER JOIN "UserHistory" uh ON uh."itemId" = d."id" AND uh."itemType" = 'document'
            INNER JOIN "User" u ON u.id = uh."userId"
            WHERE d.id = $1 AND u.id != d."owner"
        "#,
        document_id
    )
    .map(|row| row.id)
    .fetch_all(db)
    .await?;

    Ok(users)
}