mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Add /groups/get_my_list
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/controllers/GroupsController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/controllers/GroupsController.ts
									
									
									
									
									
										Normal 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()));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -4,6 +4,7 @@ import { AccountController } from "./AccountController";
 | 
			
		||||
import { UserController } from "./UserController";
 | 
			
		||||
import { ConversationsController } from "./ConversationsController";
 | 
			
		||||
import { SearchController } from "./SearchController";
 | 
			
		||||
import { GroupsController } from "./GroupsController";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Controllers routes
 | 
			
		||||
@@ -81,4 +82,8 @@ export const Routes : Route[] = [
 | 
			
		||||
	// Search controller
 | 
			
		||||
	{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
 | 
			
		||||
	{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// Groups controller
 | 
			
		||||
	{path: "/groups/get_my_list", cb: (h) => GroupsController.GetListUser(h)},
 | 
			
		||||
]
 | 
			
		||||
							
								
								
									
										31
									
								
								src/helpers/GroupsHelper.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/helpers/GroupsHelper.ts
									
									
									
									
									
										Normal 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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user