mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-07-16 22:58:04 +00:00
Like system is working
This commit is contained in:
src
@ -1,4 +1,7 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { LikesType, LikesHelper } from "../helpers/LikesHelper";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { GroupsAccessLevel } from "../entities/Group";
|
||||
|
||||
/**
|
||||
* Likes controller
|
||||
@ -13,7 +16,62 @@ export class LikesController {
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async Update(h: RequestHandler) {
|
||||
// TODO : implement
|
||||
const req_type = h.postString("type");
|
||||
const is_linking = h.postBool("like");
|
||||
|
||||
let id: number;
|
||||
let type: LikesType;
|
||||
|
||||
switch(req_type) {
|
||||
|
||||
// In case of user
|
||||
case "user":
|
||||
id = await h.postUserId("id");
|
||||
type = LikesType.USER;
|
||||
|
||||
if(!await UserHelper.CanSeeUserPage(h.getUserId(), id))
|
||||
h.error(401, "You cannot access this user information!")
|
||||
|
||||
break;
|
||||
|
||||
|
||||
// In case of post
|
||||
case "post":
|
||||
id = await h.postPostIDWithAccess("id");
|
||||
type = LikesType.POST;
|
||||
|
||||
// TODO : delete any notification targetting this user about the post
|
||||
|
||||
break;
|
||||
|
||||
|
||||
// In case of comment
|
||||
case "comment":
|
||||
id = await h.postCommentIDWithAccess("id");
|
||||
type = LikesType.COMMENT;
|
||||
break;
|
||||
|
||||
|
||||
// In case of group
|
||||
case "group":
|
||||
id = await h.postGroupIDWithAccess("id", GroupsAccessLevel.VIEW_ACCESS);
|
||||
type = LikesType.GROUP;
|
||||
break;
|
||||
|
||||
|
||||
// Default case : throw an error
|
||||
default:
|
||||
throw Error("Unsupported like type : "+req_type+" !");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Update like status
|
||||
await LikesHelper.Update(h.getUserId(), is_linking, id, type);
|
||||
|
||||
|
||||
h.success();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user