Servers: Add edit route. Ability to set icon / banner.

This commit is contained in:
Paul
2021-06-01 17:42:23 +01:00
parent bff72fa6c3
commit 6bb4501c52
9 changed files with 181 additions and 32 deletions

View File

@@ -1,4 +1,5 @@
use futures::StreamExt;
use mongodb::bson::Document;
use mongodb::options::{Collation, FindOneOptions};
use mongodb::{
bson::{doc, from_document},
@@ -223,4 +224,31 @@ impl User {
Ok(users)
}
/// Utility function to get all the server IDs the user is in.
pub async fn fetch_server_ids(&self) -> Result<Vec<String>> {
Ok(get_collection("server_members")
.find(
doc! {
"_id.user": &self.id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "find",
with: "server_members",
})?
.filter_map(async move |s| s.ok())
.collect::<Vec<Document>>()
.await
.into_iter()
.filter_map(|x| {
x.get_document("_id")
.ok()
.map(|i| i.get_str("server").ok().map(|x| x.to_string()))
})
.flatten()
.collect::<Vec<String>>())
}
}