diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 42e8fa7..409a14e 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -6,6 +6,7 @@ import { removeHTMLNodes } from "../utils/StringUtils"; import { limit_query } from "./APILimitsController"; import { Action } from "../helpers/APILimitsHelper"; import { UserController } from "./UserController"; +import { PostsController } from "./PostsController"; /** * Account controller @@ -228,7 +229,10 @@ export class AccountController { userID: data.userID, // General account information - advanced_info: await UserController.UserToAPI(data.userInfo, h, true) + advanced_info: await UserController.UserToAPI(data.userInfo, h, true), + + // User posts + posts: await Promise.all(data.postsList.map((p) => PostsController.PostToAPI(h, p))) }; diff --git a/src/entities/AccountExport.ts b/src/entities/AccountExport.ts index 268c7bb..13607be 100644 --- a/src/entities/AccountExport.ts +++ b/src/entities/AccountExport.ts @@ -5,15 +5,18 @@ */ import { User } from "./User"; +import { Post } from "./Post"; export interface AccountExportBuilder { userID: number; userInfo: User; + postsList: Post[]; } export class AccountExport implements AccountExportBuilder { userID: number; userInfo: User; + postsList: Post[]; public constructor(info: AccountExportBuilder) { for (const key in info) { diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index e57c2a2..5bb461b 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -7,6 +7,7 @@ import { time, mysql_date } from "../utils/DateUtils"; import { NewAccount } from "../entities/NewAccount"; import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User"; import { AccountExport } from "../entities/AccountExport"; +import { PostsHelper } from "./PostsHelper"; /** * Account helper @@ -383,8 +384,12 @@ export class AccountHelper { */ public static async Export(userID: number) : Promise { const data = new AccountExport({ + // General info userID: userID, - userInfo: await UserHelper.GetUserInfo(userID) + userInfo: await UserHelper.GetUserInfo(userID), + + // Export the list of posts + postsList: await PostsHelper.ExportAllPostsUser(userID) }) diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index ff83a67..bf1f77f 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -338,6 +338,26 @@ export class PostsHelper { return this.DBToPost(row); } + /** + * Get the entire list of posts created by a user & + * the posts on user page + * + * This function does not care about visibility levels & does not + * have any limit + * + * @param userID Target user ID + */ + public static async ExportAllPostsUser(userID: number) : Promise { + const list = await DatabaseHelper.Query({ + table: TABLE_NAME, + + customWhere: "ID_personne = ? OR ID_amis = ?", + customWhereArgs: [userID.toString(), userID.toString()] + }); + + return list.map((l) => this.DBToPost(l)); + } + /** * Get the access level of a user over a post *