mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Can check the right to access a comment
This commit is contained in:
@ -47,6 +47,50 @@ export class CommentsHelper {
|
||||
return results.map(this.DbToComment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a comment exists or not
|
||||
*
|
||||
* @param commentID Target comment ID
|
||||
*/
|
||||
public static async Exists(commentID: number) : Promise<boolean> {
|
||||
return await DatabaseHelper.Count({
|
||||
table: COMMENTS_TABLE,
|
||||
where: {
|
||||
ID: commentID
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a single comment
|
||||
*
|
||||
* @param commentID Target comment ID
|
||||
*/
|
||||
public static async GetSingle(commentID: number) : Promise<Comment> {
|
||||
const row = await DatabaseHelper.QueryRow({
|
||||
table: COMMENTS_TABLE,
|
||||
where: {
|
||||
ID: commentID
|
||||
}
|
||||
});
|
||||
|
||||
if(row == null)
|
||||
throw new Error("Comment " + commentID + " not found!");
|
||||
|
||||
return this.DbToComment(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of the post associated to a comment
|
||||
*
|
||||
* @param commentID Target comment ID
|
||||
*/
|
||||
public static async GetAssociatedPost(commentID: number) : Promise<number> {
|
||||
const comment = await this.GetSingle(commentID);
|
||||
|
||||
return comment.postID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently delete a comment
|
||||
*
|
||||
|
Reference in New Issue
Block a user