mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Export all user comments
This commit is contained in:
parent
336923bee7
commit
09b2eed63d
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
})
|
||||
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user