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

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-12-28 15:52:52 +00:00
import { RequestHandler } from "../entities/RequestHandler";
import { WebappHelper } from "../helpers/WebappHelper";
import { UserMembershipType } from "../entities/UserMembershipEntry";
import { FriendsController } from "./FriendsController";
import { Friend } from "../entities/Friend";
import { ConversationsController } from "./ConversationsController";
import { Conversation } from "../entities/Conversation";
2019-12-28 15:52:52 +00:00
/**
* Web application controllers
*
* @author Pierre HUBERT
*/
export class WebAppControllers {
/**
* Get the memberships of the user
*
* @param h Request handler
*/
public static async GetMemberships(h: RequestHandler) {
const list = await WebappHelper.GetUserMemberships(h.getUserId());
h.send(list.map((l) => {
switch(l.type) {
case UserMembershipType.FRIEND:
return {
type: "friend",
friend: FriendsController.FriendToAPI(<Friend>l.el)
};
case UserMembershipType.GROUP:
return {
type: "group",
id: l.el,
last_activity: l.lastActivity
}
case UserMembershipType.CONVERSATION:
return {
type: "conversation",
conv: ConversationsController.ConversationToAPI(<Conversation>l.el)
}
default:
h.error(500, "Unsupported membership type detected!");
}
2019-12-28 15:52:52 +00:00
}));
}
}