1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-27 22:18:52 +00:00

Export the list of posts of the user

This commit is contained in:
Pierre HUBERT 2020-03-25 18:44:51 +01:00
parent 4004d5fd77
commit 336923bee7
4 changed files with 34 additions and 2 deletions

View File

@ -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)))
};

View File

@ -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) {

View File

@ -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<AccountExport> {
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)
})

View File

@ -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<Post[]> {
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
*