From 66c545fc3d9f1de563b4acd69aeabb01de9b4ed9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 20 Mar 2020 18:59:35 +0100 Subject: [PATCH] Delete all posts likes --- src/helpers/LikesHelper.ts | 13 +++++++++++++ src/helpers/PostsHelper.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/helpers/LikesHelper.ts b/src/helpers/LikesHelper.ts index 753a03f..80c4b3c 100644 --- a/src/helpers/LikesHelper.ts +++ b/src/helpers/LikesHelper.ts @@ -69,4 +69,17 @@ export class LikesHelper { } }) == 1; } + + /** + * Delete all the likes related to an element + * + * @param id Target element ID + * @param type The type of target element + */ + public static async DeleteAll(id: number, type: LikesType) { + await DatabaseHelper.DeleteRows(LIKES_TABLE, { + ID_type: id, + type: LikesKindsDB[type] + }); + } } \ No newline at end of file diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index ac93c15..bf76a3c 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -5,6 +5,7 @@ import { UserHelper } from "./UserHelper"; import { GroupsHelper } from "./GroupsHelper"; import { GroupMembershipLevels } from "../entities/GroupMember"; import { mysql_date } from "../utils/DateUtils"; +import { LikesHelper, LikesType } from "./LikesHelper"; /** * Posts helper @@ -483,7 +484,10 @@ export class PostsHelper { * @param postID The ID of the post to delete */ public static async Delete(postID: number) { + const post = await this.GetSingle(postID); + // Delete all the likes associated with the post + await LikesHelper.DeleteAll(postID, LikesType.POST); } /**