1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-28 14:38:52 +00:00

Return the like status of a user over a group

This commit is contained in:
Pierre HUBERT 2019-12-25 15:31:41 +01:00
parent 91f0413963
commit 7b36e092b1
2 changed files with 21 additions and 0 deletions

View File

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

View File

@ -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<boolean> {
if(userID == 0) return false;
return await DatabaseHelper.Count({
table: LIKES_TABLE,
where: {
ID_type: id,
type: LikesKindsDB[type],
ID_personne: userID
}
}) == 1;
}
}