mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Export the list of posts of the user
This commit is contained in:
parent
4004d5fd77
commit
336923bee7
@ -6,6 +6,7 @@ import { removeHTMLNodes } from "../utils/StringUtils";
|
|||||||
import { limit_query } from "./APILimitsController";
|
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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account controller
|
* Account controller
|
||||||
@ -228,7 +229,10 @@ export class AccountController {
|
|||||||
userID: data.userID,
|
userID: data.userID,
|
||||||
|
|
||||||
// General account information
|
// 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)))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,15 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
|
import { Post } from "./Post";
|
||||||
|
|
||||||
export interface AccountExportBuilder {
|
export interface AccountExportBuilder {
|
||||||
userID: number;
|
userID: number;
|
||||||
userInfo: User;
|
userInfo: User;
|
||||||
|
postsList: Post[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AccountExport implements AccountExportBuilder {
|
export class AccountExport implements AccountExportBuilder {
|
||||||
userID: number;
|
userID: number;
|
||||||
userInfo: User;
|
userInfo: User;
|
||||||
|
postsList: Post[];
|
||||||
|
|
||||||
public constructor(info: AccountExportBuilder) {
|
public constructor(info: AccountExportBuilder) {
|
||||||
for (const key in info) {
|
for (const key in info) {
|
||||||
|
@ -7,6 +7,7 @@ import { time, mysql_date } from "../utils/DateUtils";
|
|||||||
import { NewAccount } from "../entities/NewAccount";
|
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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account helper
|
* Account helper
|
||||||
@ -383,8 +384,12 @@ export class AccountHelper {
|
|||||||
*/
|
*/
|
||||||
public static async Export(userID: number) : Promise<AccountExport> {
|
public static async Export(userID: number) : Promise<AccountExport> {
|
||||||
const data = new AccountExport({
|
const data = new AccountExport({
|
||||||
|
// General info
|
||||||
userID: userID,
|
userID: userID,
|
||||||
userInfo: await UserHelper.GetUserInfo(userID)
|
userInfo: await UserHelper.GetUserInfo(userID),
|
||||||
|
|
||||||
|
// Export the list of posts
|
||||||
|
postsList: await PostsHelper.ExportAllPostsUser(userID)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -338,6 +338,26 @@ export class PostsHelper {
|
|||||||
return this.DBToPost(row);
|
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
|
* Get the access level of a user over a post
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user