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

36 lines
875 B
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";
/**
* 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) => l.type == UserMembershipType.FRIEND ? {
// In case of friend
type: "friend",
friend: FriendsController.FriendToAPI(<Friend>l.el)
} : {
// In case of group
type: "group",
id: l.el,
last_activity: l.lastActivity
}));
}
}