From 77bb8a6ae15f9679b6344406f49a94c0d42e4a10 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 27 Mar 2020 12:08:08 +0100 Subject: [PATCH] Can delete the posts that uses a given movie --- src/helpers/PostsHelper.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index bb4f1eb..c4e8cde 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -9,6 +9,7 @@ import { LikesHelper, LikesType } from "./LikesHelper"; import { CommentsHelper } from "./CommentsHelper"; import { existsSync, unlinkSync } from "fs"; import { SurveyHelper } from "./SurveyHelper"; +import { Movie } from "../entities/Movie"; /** * Posts helper @@ -374,6 +375,30 @@ export class PostsHelper { return list.map((l) => this.DBToPost(l)); } + /** + * Get the list of posts that uses a certain movie + * + * @param movie Information about the target movie + */ + private static async GetPostsForMovie(movie: Movie) : Promise { + return (await DatabaseHelper.Query({ + table: TABLE_NAME, + where: { + idvideo: movie.id + } + })).map(this.DBToPost) + } + + /** + * Delete all the posts that includes a given movie + * + * @param movie Information about the target movie + */ + public static async DeleteAllWithMovie(movie: Movie) { + for(const post of await this.GetPostsForMovie(movie)) + await this.Delete(post.id); + } + /** * Delete all the posts of a given user *