mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 11:04:02 +00:00 
			
		
		
		
	Get information about a group
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
import { RequestHandler } from "../entities/RequestHandler";
 | 
			
		||||
import { GroupsHelper } from "../helpers/GroupsHelper";
 | 
			
		||||
import { GroupsAccessLevel } from "../entities/Group";
 | 
			
		||||
import { GroupsAccessLevel, GroupInfo, GroupVisibilityLevel, GroupPostsCreationLevel, GroupRegistrationLevel } from "../entities/Group";
 | 
			
		||||
import { GroupMembershipLevels } from "../entities/GroupMember";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Groups API controller
 | 
			
		||||
@@ -8,6 +9,43 @@ import { GroupsAccessLevel } from "../entities/Group";
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * API groups registration levels
 | 
			
		||||
 */
 | 
			
		||||
const GROUPS_REGISTRATION_LEVELS = [];
 | 
			
		||||
GROUPS_REGISTRATION_LEVELS[GroupRegistrationLevel.OPEN_REGISTRATION] = "open";
 | 
			
		||||
GROUPS_REGISTRATION_LEVELS[GroupRegistrationLevel.MODERATED_REGISTRATION] = "moderated";
 | 
			
		||||
GROUPS_REGISTRATION_LEVELS[GroupRegistrationLevel.CLOSED_REGISTRATION] = "closed";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * API groups membership levels
 | 
			
		||||
 */
 | 
			
		||||
const GROUPS_MEMBERSHIP_LEVELS = [];
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.ADMINISTRATOR] = "administrator";
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.MODERATOR] = "moderator";
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.MEMBER] = "member";
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.INVITED] = "invited";
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.PENDING] = "pending";
 | 
			
		||||
GROUPS_MEMBERSHIP_LEVELS[GroupMembershipLevels.VISITOR] = "visitor";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * API groups visibility levels
 | 
			
		||||
 */
 | 
			
		||||
const GROUPS_VISIBILITY_LEVELS = [];
 | 
			
		||||
GROUPS_VISIBILITY_LEVELS[GroupVisibilityLevel.OPEN_GROUP] = "open";
 | 
			
		||||
GROUPS_VISIBILITY_LEVELS[GroupVisibilityLevel.PRIVATE_GROUP] = "private";
 | 
			
		||||
GROUPS_VISIBILITY_LEVELS[GroupVisibilityLevel.SECRETE_GROUP] = "secrete";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * API posts creation levels
 | 
			
		||||
 */
 | 
			
		||||
const GROUPS_POSTS_LEVELS = [];
 | 
			
		||||
GROUPS_POSTS_LEVELS[GroupPostsCreationLevel.POSTS_LEVEL_MODERATORS] = "moderators";
 | 
			
		||||
GROUPS_POSTS_LEVELS[GroupPostsCreationLevel.POSTS_LEVEL_ALL_MEMBERS] = "members";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export class GroupsController {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
@@ -26,6 +64,27 @@ export class GroupsController {
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetInfoSingle(h: RequestHandler) {
 | 
			
		||||
		const groupID = await h.postGroupIDWithAccess("id", GroupsAccessLevel.LIMITED_ACCESS);
 | 
			
		||||
		h.send("Good progress!");
 | 
			
		||||
		const groupInfo = await GroupsHelper.GetInfo(groupID);
 | 
			
		||||
		
 | 
			
		||||
		h.send(this.GroupInfoToAPI(groupInfo));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a GroupInfo object into a valid API object
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param info Information about the group
 | 
			
		||||
	 * @returns Generated object
 | 
			
		||||
	 */
 | 
			
		||||
	private static GroupInfoToAPI(info: GroupInfo) : any {
 | 
			
		||||
		return {
 | 
			
		||||
			id: info.id,
 | 
			
		||||
			name: info.name,
 | 
			
		||||
			icon_url: info.logoURL,
 | 
			
		||||
			number_members: info.membersCount,
 | 
			
		||||
			visibility: GROUPS_VISIBILITY_LEVELS[info.visiblity],
 | 
			
		||||
			registration_level: GROUPS_REGISTRATION_LEVELS[info.registrationLevel],
 | 
			
		||||
			posts_level: GROUPS_POSTS_LEVELS[info.postsCreationLevel],
 | 
			
		||||
			virtual_directory: info.virtualDirectory,
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user