1
0
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:
2020-03-21 11:49:52 +01:00
parent aa0c9f4f6a
commit 16ac9fae15
4 changed files with 78 additions and 0 deletions

View File

@ -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
*