mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Can get all the membership of a user
This commit is contained in:
24
src/controllers/FriendsController.ts
Normal file
24
src/controllers/FriendsController.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Friend } from "../entities/Friend";
|
||||
|
||||
/**
|
||||
* Friends controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
export class FriendsController {
|
||||
|
||||
/**
|
||||
* Turn a friend object into an API entry
|
||||
*
|
||||
* @param friend Friend object to transform
|
||||
*/
|
||||
public static FriendToAPI(friend: Friend) : any {
|
||||
return {
|
||||
ID_friend: friend.friendID,
|
||||
accepted: friend.accepted,
|
||||
time_last_activity: friend.lastActivityTime
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import { SearchController } from "./SearchController";
|
||||
import { GroupsController } from "./GroupsController";
|
||||
import { NotificationsController } from "./NotificationsController";
|
||||
import { VirtualDirectoryController } from "./VirtualDirectoryController";
|
||||
import { WebAppControllers } from "./WebAppController";
|
||||
|
||||
/**
|
||||
* Controllers routes
|
||||
@ -152,4 +153,9 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/virtualDirectory/find", cb: (h) => VirtualDirectoryController.Find(h)},
|
||||
|
||||
|
||||
|
||||
// Web app controller
|
||||
{path: "/webApp/getMemberships", cb: (h) => WebAppControllers.GetMemberships(h)},
|
||||
|
||||
]
|
36
src/controllers/WebAppController.ts
Normal file
36
src/controllers/WebAppController.ts
Normal file
@ -0,0 +1,36 @@
|
||||
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
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user