1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Return the number of likes of a group

This commit is contained in:
2019-12-25 15:22:43 +01:00
parent f06f772420
commit 91f0413963
2 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,52 @@
import { DatabaseHelper } from "./DatabaseHelper";
/**
* Likes helper
*
* @author Pierre HUBERT
*/
/**
* Types of likes
*/
export enum LikesType {
USER = "user",
POST = "post",
COMMENT = "comment",
GROUP = "group"
}
const LIKES_TABLE = "aime";
/**
* Translation of kinds of likes for the database
*/
const LikesKindsDB = [];
LikesKindsDB[LikesType.USER] = "page";
LikesKindsDB[LikesType.POST] = "texte";
LikesKindsDB[LikesType.COMMENT] = "commentaire";
LikesKindsDB[LikesType.GROUP] = "group";
export class LikesHelper {
/**
* Count the number of likes of a specified element
*
* @param id The ID of the element to count
* @param type The type of the element
*/
public static async Count(id: number, type: LikesType) : Promise<number> {
return DatabaseHelper.Count({
table: LIKES_TABLE,
where: {
ID_type: id,
type: LikesKindsDB[type]
}
})
}
}