mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 19:14:03 +00:00 
			
		
		
		
	Add membership information when getting group information
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
import { DatabaseHelper } from "./DatabaseHelper";
 | 
			
		||||
import { GroupsAccessLevel, GroupVisibilityLevel, GroupInfo } from "../entities/Group";
 | 
			
		||||
import { GroupMembershipLevels } from "../entities/GroupMember";
 | 
			
		||||
import { GroupMembershipLevels, GroupMember } from "../entities/GroupMember";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Groups helper
 | 
			
		||||
@@ -148,6 +148,29 @@ export class GroupsHelper {
 | 
			
		||||
		return GroupsAccessLevel.NO_ACCESS;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get a user membership information
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param groupID Target group ID
 | 
			
		||||
	 * @param userID Target user ID
 | 
			
		||||
	 * @returns Membership info / null if none found
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetMembershipInfo(groupID: number, userID: number): Promise<GroupMember> {
 | 
			
		||||
		const data = await DatabaseHelper.QueryRow({
 | 
			
		||||
			table: GROUPS_MEMBERS_TABLE,
 | 
			
		||||
			where: {
 | 
			
		||||
				groups_id: groupID,
 | 
			
		||||
				user_id: userID
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if(data == null)
 | 
			
		||||
			return null;
 | 
			
		||||
		
 | 
			
		||||
		return this.DbToGroupMember(data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Count the number of members of a group
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -182,4 +205,21 @@ export class GroupsHelper {
 | 
			
		||||
			virtualDirectory: (row.virtual_directory != null && row.virtual_directory && row.virtual_directory != "null" ? row.virtual_directory : undefined)
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a database entry into a group membership information object
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param row Database entry
 | 
			
		||||
	 * @returns Generated object
 | 
			
		||||
	 */
 | 
			
		||||
	private static async DbToGroupMember(row: any) : Promise<GroupMember> {
 | 
			
		||||
		return new GroupMember({
 | 
			
		||||
			id: row.id,
 | 
			
		||||
			groupID: row.groups_id,
 | 
			
		||||
			userID: row.user_id,
 | 
			
		||||
			timeCreate: row.time_create,
 | 
			
		||||
			level: row.level,
 | 
			
		||||
			following: row.following == 1
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user