mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 19:14:03 +00:00 
			
		
		
		
	Delete notifications related with a post when deleting it
This commit is contained in:
		@@ -349,8 +349,6 @@ export class PostsController {
 | 
			
		||||
 | 
			
		||||
		await PostsHelper.Delete(postID);
 | 
			
		||||
 | 
			
		||||
		// TODO : delete all the notifications related with the post
 | 
			
		||||
 | 
			
		||||
		h.success();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -297,6 +297,18 @@ export class NotificationsHelper {
 | 
			
		||||
		}));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Delete all the notification related with a post
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param postID Target post id
 | 
			
		||||
	 */
 | 
			
		||||
	public static async DeleteAllRelatedWithPost(postID: number) {
 | 
			
		||||
		await this.Delete(new Notif({
 | 
			
		||||
			onElemType: NotifElemType.POST,
 | 
			
		||||
			onElemID: postID
 | 
			
		||||
		}));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Count the number of unread notifications of a user
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ import { CommentsHelper } from "./CommentsHelper";
 | 
			
		||||
import { existsSync, unlinkSync } from "fs";
 | 
			
		||||
import { SurveyHelper } from "./SurveyHelper";
 | 
			
		||||
import { Movie } from "../entities/Movie";
 | 
			
		||||
import { NotificationsHelper } from "./NotificationsHelper";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Posts helper
 | 
			
		||||
@@ -563,6 +564,9 @@ export class PostsHelper {
 | 
			
		||||
	public static async Delete(postID: number) {
 | 
			
		||||
		const post = await this.GetSingle(postID);
 | 
			
		||||
 | 
			
		||||
		// Delete all the notifications related with the post
 | 
			
		||||
		await NotificationsHelper.DeleteAllRelatedWithPost(postID);
 | 
			
		||||
 | 
			
		||||
		// Delete all the likes associated with the post
 | 
			
		||||
		await LikesHelper.DeleteAll(postID, LikesType.POST);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user