From aa9ae35ea324d0ed9f79c4041cffb6cc674fea0e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 27 Mar 2020 14:32:40 +0100 Subject: [PATCH] Can delete all the notifications related with a specified user --- src/helpers/AccountHelper.ts | 4 ++++ src/helpers/NotificationsHelper.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index e3c588a..23fc5d0 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -15,6 +15,7 @@ import { MoviesHelper } from "./MoviesHelper"; import { ConversationsHelper } from "./ConversationsHelper"; import { FriendsHelper } from "./FriendsHelper"; import { GroupsHelper } from "./GroupsHelper"; +import { NotificationsHelper } from "./NotificationsHelper"; /** * Account helper @@ -465,6 +466,9 @@ export class AccountHelper { // Remove the user from all its conversations await ConversationsHelper.DeleteAllUserConversations(userID); + + // Delete all the notifications related with the user + await NotificationsHelper.DeleteAllRelatedWithUser(userID); */ // TODO : continue work diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index 9ada9b5..0e3003b 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -282,6 +282,21 @@ export class NotificationsHelper { await this.Delete(n); } + /** + * Delete all the notifications related with a specified user + * + * @param userID Target user ID + */ + public static async DeleteAllRelatedWithUser(userID: number) { + // Delete all the notifications targetting the user + await this.DeleteAllUser(userID); + + // Delete all the notifications created by the user + await this.Delete(new Notif({ + fromUserID: userID + })); + } + /** * Count the number of unread notifications of a user *