diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index 35ad18a..a7c2b75 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -162,6 +162,7 @@ export class GroupsController { data["url"] = info.url ? info.hasURL : "null"; data["number_likes"] = await LikesHelper.Count(info.id, LikesType.GROUP); + data["is_liking"] = h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), info.id, LikesType.GROUP) : false; } return data; diff --git a/src/helpers/LikesHelper.ts b/src/helpers/LikesHelper.ts index 229bf93..753a03f 100644 --- a/src/helpers/LikesHelper.ts +++ b/src/helpers/LikesHelper.ts @@ -49,4 +49,24 @@ export class LikesHelper { }) } + + /** + * Check out whether the user likes an element or not + * + * @param userID ID of the user + * @param id ID of the thing to check + * @param type The kind of the element + */ + public static async IsLiking(userID: number, id: number, type: LikesType) : Promise { + if(userID == 0) return false; + + return await DatabaseHelper.Count({ + table: LIKES_TABLE, + where: { + ID_type: id, + type: LikesKindsDB[type], + ID_personne: userID + } + }) == 1; + } } \ No newline at end of file