1
0
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:
2020-03-21 14:45:03 +01:00
parent aa21a2a5e6
commit 3eac46ac55
2 changed files with 96 additions and 1 deletions

View File

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