diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 588fc4e..64f5cdc 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -11,6 +11,7 @@ import { CommentsController } from "./CommentsController"; import { LikesController } from "./LikesController"; import { SurveyController } from "./SurveyController"; import { MoviesController } from "./MoviesController"; +import { ConversationsController } from "./ConversationsController"; /** * Account controller @@ -249,6 +250,9 @@ export class AccountController { // User movies movies: data.movies.map(MoviesController.MovieToAPI), + + // Conversations messages + all_conversation_messages: data.conversationMessages.map(ConversationsController.ConversationMessageToAPI) }; diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 90e7ef6..a3c73fb 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -394,7 +394,7 @@ export class ConversationsController { * * @param c Information about the conversation */ - private static ConversationMessageToAPI(c: ConversationMessage) : any { + public static ConversationMessageToAPI(c: ConversationMessage) : any { return { ID: c.id, ID_user: c.userID, diff --git a/src/entities/AccountExport.ts b/src/entities/AccountExport.ts index 1f3bd1d..8e8269c 100644 --- a/src/entities/AccountExport.ts +++ b/src/entities/AccountExport.ts @@ -10,6 +10,7 @@ import { Comment } from "./Comment"; import { UserLike } from "./UserLike"; import { SurveyResponse } from "./SurveyResponse"; import { Movie } from "./Movie"; +import { ConversationMessage } from "./ConversationMessage"; export interface AccountExportBuilder { userID: number; @@ -19,6 +20,7 @@ export interface AccountExportBuilder { likes: UserLike[]; surveyResponses: SurveyResponse[]; movies: Movie[]; + conversationMessages: ConversationMessage[]; } export class AccountExport implements AccountExportBuilder { @@ -29,6 +31,7 @@ export class AccountExport implements AccountExportBuilder { likes: UserLike[]; surveyResponses: SurveyResponse[]; movies: Movie[]; + conversationMessages: ConversationMessage[]; public constructor(info: AccountExportBuilder) { for (const key in info) { diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index af4faf5..7b95aa7 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -12,6 +12,7 @@ import { CommentsHelper } from "./CommentsHelper"; import { LikesHelper } from "./LikesHelper"; import { SurveyHelper } from "./SurveyHelper"; import { MoviesHelper } from "./MoviesHelper"; +import { ConversationsHelper } from "./ConversationsHelper"; /** * Account helper @@ -406,6 +407,9 @@ export class AccountHelper { // User movies movies: await MoviesHelper.GetListUser(userID), + + // Conversation messages + conversationMessages: await ConversationsHelper.ExportAllMessages(userID), }) diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index a7b913f..0aacded 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -352,6 +352,20 @@ export class ConversationsHelper { .map(m => this.DBToConversationMessage(convID, m)).reverse(); } + /** + * Export all the conversation messages of a given user + * + * @param userID Target user ID + */ + public static async ExportAllMessages(userID: number) : Promise { + return (await DatabaseHelper.Query({ + table: MESSAGES_TABLE, + where: { + user_id: userID + } + })).map(m => this.DBToConversationMessage(m.conv_id, m)); + } + /** * Mark the user has seen the last messages of the conversation *