mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Return the like status of a user over a group
This commit is contained in:
parent
91f0413963
commit
7b36e092b1
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user