diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index d522389..11372f3 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -349,8 +349,6 @@ export class PostsController { await PostsHelper.Delete(postID); - // TODO : delete all the notifications related with the post - h.success(); } diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index 0e3003b..768d4d4 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -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 * diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index c4e8cde..25af8e3 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -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);