1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Export all user comments

This commit is contained in:
Pierre HUBERT 2020-03-25 18:55:25 +01:00
parent 336923bee7
commit 09b2eed63d
4 changed files with 28 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import { limit_query } from "./APILimitsController";
import { Action } from "../helpers/APILimitsHelper"; import { Action } from "../helpers/APILimitsHelper";
import { UserController } from "./UserController"; import { UserController } from "./UserController";
import { PostsController } from "./PostsController"; import { PostsController } from "./PostsController";
import { CommentsController } from "./CommentsController";
/** /**
* Account controller * Account controller
@ -232,12 +233,15 @@ export class AccountController {
advanced_info: await UserController.UserToAPI(data.userInfo, h, true), advanced_info: await UserController.UserToAPI(data.userInfo, h, true),
// User posts // 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); h.send(out);

View File

@ -6,17 +6,20 @@
import { User } from "./User"; import { User } from "./User";
import { Post } from "./Post"; import { Post } from "./Post";
import { Comment } from "./Comment";
export interface AccountExportBuilder { export interface AccountExportBuilder {
userID: number; userID: number;
userInfo: User; userInfo: User;
postsList: Post[]; postsList: Post[];
comments: Comment[];
} }
export class AccountExport implements AccountExportBuilder { export class AccountExport implements AccountExportBuilder {
userID: number; userID: number;
userInfo: User; userInfo: User;
postsList: Post[]; postsList: Post[];
comments: Comment[];
public constructor(info: AccountExportBuilder) { public constructor(info: AccountExportBuilder) {
for (const key in info) { for (const key in info) {

View File

@ -8,6 +8,7 @@ import { NewAccount } from "../entities/NewAccount";
import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User"; import { GeneralSettings, UserPageStatus, LangSettings, SecuritySettings } from "../entities/User";
import { AccountExport } from "../entities/AccountExport"; import { AccountExport } from "../entities/AccountExport";
import { PostsHelper } from "./PostsHelper"; import { PostsHelper } from "./PostsHelper";
import { CommentsHelper } from "./CommentsHelper";
/** /**
* Account helper * Account helper
@ -389,7 +390,10 @@ export class AccountHelper {
userInfo: await UserHelper.GetUserInfo(userID), userInfo: await UserHelper.GetUserInfo(userID),
// Export the list of posts // 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)
}) })

View File

@ -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<Comment[]> {
return (await DatabaseHelper.Query({
table: COMMENTS_TABLE,
where: {
ID_personne: userID
}
})).map((row) => this.DbToComment(row));
}
/** /**
* Turn a database entry into a Comment object * Turn a database entry into a Comment object
* *