mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Get & return the comments of a post
This commit is contained in:
		
							
								
								
									
										46
									
								
								src/helpers/CommentsHelper.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/helpers/CommentsHelper.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 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
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user