Add member_count to /invites/:id

This commit is contained in:
jan0660
2021-07-25 16:49:27 +02:00
parent 682b6cbd9f
commit ca04f4d510
2 changed files with 17 additions and 0 deletions

View File

@@ -425,4 +425,19 @@ impl Server {
Ok(())
}
pub async fn get_member_count(id: &str) -> Result<i64> {
Ok(get_collection("server_members")
.count_documents(
doc! {
"_id.server": id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "count_documents",
with: "server_members",
})?)
}
}

View File

@@ -21,6 +21,7 @@ pub enum InviteResponse {
user_name: String,
#[serde(skip_serializing_if = "Option::is_none")]
user_avatar: Option<File>,
member_count: i64,
},
}
@@ -41,6 +42,7 @@ pub async fn req(target: Ref) -> Result<JsonValue> {
let server = Ref::from_unchecked(server).fetch_server().await?;
Ok(json!(InviteResponse::Server {
member_count: Server::get_member_count(&server.id).await?,
server_id: server.id,
server_name: server.name,
server_icon: server.icon,