mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-27 22:18:52 +00:00
Export all conversation messages
This commit is contained in:
parent
536df2931b
commit
58877e0100
@ -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)
|
||||
};
|
||||
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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),
|
||||
})
|
||||
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user