From 30200b93010737f2c04e17a9265c2bb79642a80f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 27 Mar 2020 11:42:18 +0100 Subject: [PATCH] Can delete all the posts of a user --- src/helpers/AccountHelper.ts | 5 ++++- src/helpers/PostsHelper.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index ae592d5..13d96cb 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -447,8 +447,11 @@ export class AccountHelper { // Delete all user comments await CommentsHelper.DeleteAllUser(userID); - */ + // Delete all user posts + await PostsHelper.DeleteAllUser(userID); + */ + // TODO : continue work } diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index b51c978..bb4f1eb 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -374,6 +374,19 @@ export class PostsHelper { return list.map((l) => this.DBToPost(l)); } + /** + * Delete all the posts of a given user + * + * This method deletes both the posts created by the user + * & the posts created on user page + * + * @param userID Target user ID + */ + public static async DeleteAllUser(userID: number) { + for(const post of await this.ExportAllPostsUser(userID)) + await this.Delete(post.id); + } + /** * Get the access level of a user over a post *