1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 06:49:23 +00:00

Export all conversation messages

This commit is contained in:
Pierre HUBERT 2020-03-26 13:05:14 +01:00
parent 536df2931b
commit 58877e0100
5 changed files with 26 additions and 1 deletions

View File

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

View File

@ -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,

View File

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

View File

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

View File

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