]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/comment/delete.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / api_crud / src / comment / delete.rs
index 864daded8cad381e9ca6a43877928bd7ad2e3207..c42924de74ab8109590b2988204eb1878274ab50 100644 (file)
@@ -14,7 +14,7 @@ use lemmy_db_schema::{
   traits::Crud,
 };
 use lemmy_db_views::structs::CommentView;
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
 
 #[async_trait::async_trait(?Send)]
 impl PerformCrud for DeleteComment {
@@ -26,37 +26,37 @@ impl PerformCrud for DeleteComment {
     let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
 
     let comment_id = data.comment_id;
-    let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+    let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
 
     // Dont delete it if its already been deleted.
     if orig_comment.comment.deleted == data.deleted {
-      return Err(LemmyError::from_message("couldnt_update_comment"));
+      return Err(LemmyErrorType::CouldntUpdateComment)?;
     }
 
     check_community_ban(
       local_user_view.person.id,
       orig_comment.community.id,
-      context.pool(),
+      &mut context.pool(),
     )
     .await?;
 
     // Verify that only the creator can delete
     if local_user_view.person.id != orig_comment.creator.id {
-      return Err(LemmyError::from_message("no_comment_edit_allowed"));
+      return Err(LemmyErrorType::NoCommentEditAllowed)?;
     }
 
     // Do the delete
     let deleted = data.deleted;
     let updated_comment = Comment::update(
-      context.pool(),
+      &mut context.pool(),
       comment_id,
       &CommentUpdateForm::builder().deleted(Some(deleted)).build(),
     )
     .await
-    .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
+    .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
 
     let post_id = updated_comment.post_id;
-    let post = Post::read(context.pool(), post_id).await?;
+    let post = Post::read(&mut context.pool(), post_id).await?;
     let recipient_ids = send_local_notifs(
       vec![],
       &updated_comment,