1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-26 07:19:23 +00:00

Add /groups/get_my_list

This commit is contained in:
Pierre HUBERT 2019-12-13 17:49:58 +01:00
parent 8737607b53
commit ee6579efa0
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { RequestHandler } from "../entities/RequestHandler";
import { GroupsHelper } from "../helpers/GroupsHelper";
/**
* Groups API controller
*
* @author Pierre HUBERT
*/
export class GroupsController {
/**
* Get the list of groups of the user
*
* @param h Request handler
*/
public static async GetListUser(h: RequestHandler) {
h.send(await GroupsHelper.GetListUser(h.getUserId()));
}
}

View File

@ -4,6 +4,7 @@ import { AccountController } from "./AccountController";
import { UserController } from "./UserController"; import { UserController } from "./UserController";
import { ConversationsController } from "./ConversationsController"; import { ConversationsController } from "./ConversationsController";
import { SearchController } from "./SearchController"; import { SearchController } from "./SearchController";
import { GroupsController } from "./GroupsController";
/** /**
* Controllers routes * Controllers routes
@ -81,4 +82,8 @@ export const Routes : Route[] = [
// Search controller // Search controller
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)}, {path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy {path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
// Groups controller
{path: "/groups/get_my_list", cb: (h) => GroupsController.GetListUser(h)},
] ]

View File

@ -0,0 +1,31 @@
import { DatabaseHelper } from "./DatabaseHelper";
/**
* Groups helper
*
* @author Pierre HUBERT
*/
const GROUPS_LIST_TABLE = "comunic_groups";
const GROUPS_MEMBERS_TABLE = "comunic_groups_members";
export class GroupsHelper {
/**
* Get the list of groups of a user
*
* @param userID Target user ID
*/
public static async GetListUser(userID: number) : Promise<Array<number>> {
const list = await DatabaseHelper.Query({
table: GROUPS_MEMBERS_TABLE,
where: {
user_id: userID
},
fields: ["groups_id"]
});
return list.map(e => e.groups_id);
}
}