1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-21 21:09:22 +00:00

Delete notifications related with a post when deleting it

This commit is contained in:
Pierre HUBERT 2020-03-28 14:08:47 +01:00
parent f569e9163d
commit bef85d2d91
3 changed files with 16 additions and 2 deletions

View File

@ -349,8 +349,6 @@ export class PostsController {
await PostsHelper.Delete(postID);
// TODO : delete all the notifications related with the post
h.success();
}

View File

@ -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
*

View File

@ -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);