mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Can delete comments
This commit is contained in:
		@@ -36,4 +36,8 @@ export class Comment implements CommentBuilder {
 | 
				
			|||||||
	get imageURL() : string {
 | 
						get imageURL() : string {
 | 
				
			||||||
		return pathUserData(this.imagePath);
 | 
							return pathUserData(this.imagePath);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						get imageSysPath() : string {
 | 
				
			||||||
 | 
							return pathUserData(this.imagePath, true);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1,5 +1,7 @@
 | 
				
			|||||||
import { Comment } from "../entities/Comment";
 | 
					import { Comment } from "../entities/Comment";
 | 
				
			||||||
import { DatabaseHelper } from "./DatabaseHelper";
 | 
					import { DatabaseHelper } from "./DatabaseHelper";
 | 
				
			||||||
 | 
					import { unlinkSync, existsSync } from "fs";
 | 
				
			||||||
 | 
					import { LikesHelper, LikesType } from "./LikesHelper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Comments helper
 | 
					 * Comments helper
 | 
				
			||||||
@@ -28,13 +30,38 @@ export class CommentsHelper {
 | 
				
			|||||||
		return results.map(this.DbToComment);
 | 
							return results.map(this.DbToComment);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Permanently delete a comment
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param comment Information about the comment to delete
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static async Delete(comment: Comment) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete associated image (if any)
 | 
				
			||||||
 | 
							if(comment.hasImage && existsSync(comment.imageSysPath)) {
 | 
				
			||||||
 | 
								unlinkSync(comment.imageSysPath);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete likes associated with the comment
 | 
				
			||||||
 | 
							await LikesHelper.DeleteAll(comment.id, LikesType.COMMENT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete the comment from the database
 | 
				
			||||||
 | 
							await DatabaseHelper.DeleteRows(COMMENTS_TABLE, {
 | 
				
			||||||
 | 
								ID: comment.id
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Delete all the comments associated to a post
 | 
						 * Delete all the comments associated to a post
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param postID Target post ID
 | 
						 * @param postID Target post ID
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static async DeleteAll(postID: number) {
 | 
						public static async DeleteAll(postID: number) {
 | 
				
			||||||
		// TODO : implement
 | 
							
 | 
				
			||||||
 | 
							// Get the comments of the post
 | 
				
			||||||
 | 
							for(const comment of await this.Get(postID)) {
 | 
				
			||||||
 | 
								await this.Delete(comment);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user