2020-01-03 16:31:39 +00:00
|
|
|
import { RequestHandler } from "../entities/RequestHandler";
|
|
|
|
import { Comment } from "../entities/Comment";
|
|
|
|
import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Comments controller
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
export class CommentsController {
|
|
|
|
|
2020-03-21 08:20:34 +00:00
|
|
|
/**
|
|
|
|
* Create a new comment
|
|
|
|
*
|
|
|
|
* @param h Request handler
|
|
|
|
*/
|
|
|
|
public static async Create(h: RequestHandler) {
|
|
|
|
const postID = await h.postPostIDWithAccess("postID");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-03 16:31:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn a list of comment object into API entries
|
|
|
|
*
|
|
|
|
* @param h Request handler
|
|
|
|
* @param l List of comments
|
|
|
|
*/
|
|
|
|
public static async CommentsToAPI(h: RequestHandler, l: Comment[]) : Promise<Array<any>> {
|
|
|
|
const list = [];
|
|
|
|
for (const comment of l) {
|
|
|
|
list.push(await this.CommentToAPI(h, comment));
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Turn a comment into an API object
|
|
|
|
*
|
|
|
|
* @param h Request handler
|
|
|
|
* @param c Comment
|
|
|
|
*/
|
|
|
|
public static async CommentToAPI(h: RequestHandler, c: Comment) : Promise<any> {
|
|
|
|
return {
|
|
|
|
ID: c.id,
|
|
|
|
userID: c.userID,
|
|
|
|
postID: c.postID,
|
|
|
|
time_sent: c.timeSent,
|
|
|
|
content: c.content,
|
|
|
|
img_path: c.hasImage ? c.imagePath : null,
|
|
|
|
img_url: c.hasImage ? c.imageURL : null,
|
|
|
|
likes: await LikesHelper.Count(c.id, LikesType.COMMENT),
|
|
|
|
userlike: h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), c.id, LikesType.COMMENT) : false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|