1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00
comunicapiv2/src/helpers/CommentsHelper.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-01-03 16:31:39 +00:00
import { Comment } from "../entities/Comment";
import { DatabaseHelper } from "./DatabaseHelper";
/**
* Comments helper
*
* @author Pierre HUBERT
*/
const COMMENTS_TABLE = "commentaires";
export class CommentsHelper {
/**
* Get the comments of a POST
*
* @param postID Target post ID
*/
public static async Get(postID: number) : Promise<Array<Comment>> {
const results = await DatabaseHelper.Query({
table: COMMENTS_TABLE,
where: {
ID_texte: postID
},
order: "ID"
});
return results.map(this.DbToComment);
}
2020-03-20 18:07:19 +00:00
/**
* Delete all the comments associated to a post
*
* @param postID Target post ID
*/
public static async DeleteAll(postID: number) {
// TODO : implement
}
2020-01-03 16:31:39 +00:00
/**
* Turn a database entry into a Comment object
*
* @param row Database entry
*/
private static DbToComment(row: any) : Comment {
return new Comment({
id: row.ID,
userID: row.ID_personne,
postID: row.ID_texte,
timeSent: row.time_insert == null ? new Date(row.date_envoi).getTime() / 100 : row.time_insert,
content: row.commentaire,
imagePath: (row.image_commentaire != null && row.image_commentaire != "") ? row.image_commentaire.replace("file:", "") : null
});
}
}