Delete old avatar; fix database migration.

This commit is contained in:
Paul
2021-05-01 17:12:51 +01:00
parent f135a57a9b
commit 59b18fd376
4 changed files with 27 additions and 18 deletions

View File

@@ -86,4 +86,25 @@ impl File {
Err(Error::UnknownAttachment)
}
}
pub async fn delete(&self) -> Result<()> {
get_collection("attachments")
.update_one(
doc! {
"_id": &self.id
},
doc! {
"$set": {
"deleted": true
}
},
None,
)
.await
.map(|_| ())
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "attachment",
})
}
}

View File

@@ -236,23 +236,7 @@ impl Message {
pub async fn delete(&self) -> Result<()> {
if let Some(attachment) = &self.attachment {
get_collection("attachments")
.update_one(
doc! {
"_id": &attachment.id
},
doc! {
"$set": {
"deleted": true
}
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "attachment",
})?;
attachment.delete().await?;
}
get_collection("messages")