mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Like system is working
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { mysql_date } from "../utils/DateUtils";
|
||||
|
||||
/**
|
||||
* Likes helper
|
||||
@ -70,6 +71,42 @@ export class LikesHelper {
|
||||
}) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update like status
|
||||
*
|
||||
* @param userID The ID of the user updating like status
|
||||
* @param isLiking New like status of the user
|
||||
* @param id The ID of the component element to update
|
||||
* @param kind The kind of the element
|
||||
*/
|
||||
public static async Update(userID: number, isLiking: boolean, id: number, kind: LikesType) {
|
||||
|
||||
// If not liking anymore
|
||||
if(!isLiking) {
|
||||
await DatabaseHelper.DeleteRows(LIKES_TABLE, {
|
||||
ID_personne: userID,
|
||||
ID_type: id,
|
||||
type: LikesKindsDB[kind]
|
||||
})
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Else we make the user liking the element
|
||||
|
||||
// Check if the user is already liking the element
|
||||
if(await this.IsLiking(userID, id, kind))
|
||||
return;
|
||||
|
||||
// Insert in the database
|
||||
await DatabaseHelper.InsertRow(LIKES_TABLE, {
|
||||
ID_personne: userID,
|
||||
ID_type: id,
|
||||
Date_envoi: mysql_date(),
|
||||
type: LikesKindsDB[kind]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the likes related to an element
|
||||
*
|
||||
|
Reference in New Issue
Block a user