Skip to content
use crate::db::Database;

impl Database {
    pub async fn create_invite(&self, token: &str) -> Result<(), String> {
        self.conn()
            .await?
            .execute(
                "INSERT INTO invites (token, created_at) VALUES (?1, ?2)",
                turso::params![token, chrono::Utc::now().to_rfc3339()],
            )
            .await
            .map_err(|e| e.to_string())?;
        Ok(())
    }

    pub async fn invite_exists(&self, token: &str) -> Result<bool, String> {
        let mut rows = self
            .conn()
            .await?
            .query(
                "SELECT 1 FROM invites WHERE token = ?1",
                turso::params![token],
            )
            .await
            .map_err(|e| e.to_string())?;
        Ok(rows.next().await.map_err(|e| e.to_string())?.is_some())
    }
}