mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 11:04:02 +00:00 
			
		
		
		
	Can get information about a single post
This commit is contained in:
		@@ -230,6 +230,37 @@ export class PostsHelper {
 | 
			
		||||
		return results.map((r) => this.DBToPost(r));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information about a single post
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param postID Target post ID
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetSingle(postID: number) : Promise<Post> {
 | 
			
		||||
		const row = await DatabaseHelper.QueryRow({
 | 
			
		||||
			table: TABLE_NAME,
 | 
			
		||||
			where: {
 | 
			
		||||
				ID: postID
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if(row == null)
 | 
			
		||||
			throw new Error("Post " + postID + " not found!");
 | 
			
		||||
		
 | 
			
		||||
		return this.DBToPost(row);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get the access level of a user over a post
 | 
			
		||||
	 * 
 | 
			
		||||
	 * This is a convenience function
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param userID Target user ID
 | 
			
		||||
	 * @param postID Target post ID
 | 
			
		||||
	 */
 | 
			
		||||
	public static async GetAccessLevelFromPostID(userID: number, postID: number) : Promise<PostAccessLevel> {
 | 
			
		||||
		return await this.GetAccessLevel(userID, await this.GetSingle(postID));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get the access level of a user over a post
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -312,6 +343,20 @@ export class PostsHelper {
 | 
			
		||||
		return !post.isUserPage || await UserHelper.AllowComments(post.userPageID);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check out whether a post exists or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param postID The id of the post to check
 | 
			
		||||
	 */
 | 
			
		||||
	public static async Exists(postID: number) : Promise<boolean> {
 | 
			
		||||
		return await DatabaseHelper.Count({
 | 
			
		||||
			table: TABLE_NAME,
 | 
			
		||||
			where: {
 | 
			
		||||
				ID: postID
 | 
			
		||||
			}
 | 
			
		||||
		}) > 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a database entry into a row object
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user