From 09b2eed63d608167dc4a99c21e0775669583fb62 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 25 Mar 2020 18:55:25 +0100 Subject: [PATCH] Export all user comments --- src/controllers/AccountController.ts | 8 ++++++-- src/entities/AccountExport.ts | 3 +++ src/helpers/AccountHelper.ts | 6 +++++- src/helpers/CommentsHelper.ts | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 409a14e..1491c1c 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -7,6 +7,7 @@ import { limit_query } from "./APILimitsController"; import { Action } from "../helpers/APILimitsHelper"; import { UserController } from "./UserController"; import { PostsController } from "./PostsController"; +import { CommentsController } from "./CommentsController"; /** * Account controller @@ -232,12 +233,15 @@ export class AccountController { advanced_info: await UserController.UserToAPI(data.userInfo, h, true), // User posts - posts: await Promise.all(data.postsList.map((p) => PostsController.PostToAPI(h, p))) + posts: await Promise.all(data.postsList.map((p) => PostsController.PostToAPI(h, p))), + + // User comments + comments: await CommentsController.CommentsToAPI(h, data.comments), }; - // TODO : continue + // TODO : continue (additional user info) h.send(out); diff --git a/src/entities/AccountExport.ts b/src/entities/AccountExport.ts index 13607be..32ee09d 100644 --- a/src/entities/AccountExport.ts +++ b/src/entities/AccountExport.ts @@ -6,17 +6,20 @@ import { User } from "./User"; import { Post } from "./Post"; +import { Comment } from "./Comment"; export interface AccountExportBuilder { userID: number; userInfo: User; postsList: Post[]; + comments: Comment[]; } export class AccountExport implements AccountExportBuilder { userID: number; userInfo: User; postsList: Post[]; + comments: Comment[]; public constructor(info: AccountExportBuilder) { for (const key in info) { diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index 5bb461b..b49ed1d 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -8,6 +8,7 @@ import { NewAccount } from "../entities/NewAccount"; import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User"; import { AccountExport } from "../entities/AccountExport"; import { PostsHelper } from "./PostsHelper"; +import { CommentsHelper } from "./CommentsHelper"; /** * Account helper @@ -389,7 +390,10 @@ export class AccountHelper { userInfo: await UserHelper.GetUserInfo(userID), // Export the list of posts - postsList: await PostsHelper.ExportAllPostsUser(userID) + postsList: await PostsHelper.ExportAllPostsUser(userID), + + // Export the list of comments + comments: await CommentsHelper.ExportAllUser(userID) }) diff --git a/src/helpers/CommentsHelper.ts b/src/helpers/CommentsHelper.ts index f22eafd..c9a4861 100644 --- a/src/helpers/CommentsHelper.ts +++ b/src/helpers/CommentsHelper.ts @@ -158,6 +158,20 @@ export class CommentsHelper { } } + /** + * Get all the comments sent by a specified user + * + * @param userID Target user ID + */ + public static async ExportAllUser(userID: number) : Promise { + return (await DatabaseHelper.Query({ + table: COMMENTS_TABLE, + where: { + ID_personne: userID + } + })).map((row) => this.DbToComment(row)); + } + /** * Turn a database entry into a Comment object *