1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00
comunicapiv2/src/controllers/ConversationsController.ts

39 lines
943 B
TypeScript
Raw Normal View History

2019-11-23 17:41:13 +00:00
import { RequestHandler } from "../entities/RequestHandler";
import { ConversationsHelper } from "../helpers/ConversationsHelper";
import { Conversation } from "../entities/Conversation";
/**
* Conversations controller
*
* @author Pierre HUBERT
*/
export class ConversationsController {
/**
* Get the list of conversations of the user
*
* @param handler
*/
public static async GetList(handler: RequestHandler) {
const list = await ConversationsHelper.GetListUser(handler.getUserId());
handler.send(list.map(c => this.ConversationToAPI(c)));
}
/**
* Turn a conversation object into an API entry
*
* @param c
*/
private static ConversationToAPI(c : Conversation) : any {
return {
ID: c.id,
ID_owner: c.ownerID,
last_active: c.lastActive,
name: c.name.length > 0 ? c.name : false,
following: c.following ? 1 : 0,
saw_last_message: c.sawLastMessage ? 1 : 0,
members: c.members
};
}
}