forked from jmug/stoatchat
Run cargo fmt.
This commit is contained in:
@@ -23,31 +23,39 @@ pub struct Data {
|
||||
#[patch("/<_ignore_id>", data = "<data>")]
|
||||
pub async fn req(user: User, mut data: Json<Data>, _ignore_id: String) -> Result<()> {
|
||||
if data.0.status.is_none() && data.0.profile.is_none() && data.0.avatar.is_none() {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
let mut set = to_document(&data.0).map_err(|_| Error::DatabaseError { operation: "to_document", with: "data" })?;
|
||||
let mut set = to_document(&data.0).map_err(|_| Error::DatabaseError {
|
||||
operation: "to_document",
|
||||
with: "data",
|
||||
})?;
|
||||
|
||||
let avatar = std::mem::replace(&mut data.0.avatar, None);
|
||||
let attachment = if let Some(attachment_id) = avatar {
|
||||
let attachment = File::find_and_use(&attachment_id, "avatars", "user", &user.id).await?;
|
||||
set.insert("avatar", to_document(&attachment).map_err(|_| Error::DatabaseError { operation: "to_document", with: "attachment" })?);
|
||||
set.insert(
|
||||
"avatar",
|
||||
to_document(&attachment).map_err(|_| Error::DatabaseError {
|
||||
operation: "to_document",
|
||||
with: "attachment",
|
||||
})?,
|
||||
);
|
||||
Some(attachment)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
get_collection("users")
|
||||
.update_one(
|
||||
doc! { "_id": &user.id },
|
||||
doc! { "$set": set },
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "user" })?;
|
||||
.update_one(doc! { "_id": &user.id }, doc! { "$set": set }, None)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
if let Some(status) = data.0.status {
|
||||
ClientboundNotification::UserUpdate {
|
||||
|
||||
Reference in New Issue
Block a user