Allow users with no invites to be fetched from the API

Nathan Sobo created

Change summary

crates/collab/src/api.rs |  1 +
crates/collab/src/db.rs  | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)

Detailed changes

crates/collab/src/api.rs 🔗

@@ -229,6 +229,7 @@ async fn create_users(
     Ok(Json(users))
 }
 
+#[derive(Debug, Deserialize)]
 struct GetUsersWithNoInvites {
     invited_by_another_user: bool,
 }

crates/collab/src/db.rs 🔗

@@ -262,15 +262,17 @@ impl Db for PostgresDb {
     }
 
     async fn get_users_with_no_invites(&self, invited_by_another_user: bool) -> Result<Vec<User>> {
-        let query = "
+        let query = format!(
+            "
             SELECT users.*
             FROM users
             WHERE invite_count = 0
-            ";
-        Ok(sqlx::query_as(query)
-            .bind(&ids)
-            .fetch_all(&self.pool)
-            .await?)
+            AND inviter_id IS{} NULL
+            ",
+            if invited_by_another_user { " NOT" } else { "" }
+        );
+
+        Ok(sqlx::query_as(&query).fetch_all(&self.pool).await?)
     }
 
     async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
@@ -2188,6 +2190,10 @@ pub mod tests {
             Ok(ids.iter().filter_map(|id| users.get(id).cloned()).collect())
         }
 
+        async fn get_users_with_no_invites(&self, _: bool) -> Result<Vec<User>> {
+            unimplemented!()
+        }
+
         async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
             Ok(self
                 .users