mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Start group deletion
This commit is contained in:
		@@ -570,8 +570,9 @@ export class GroupsController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		await h.needUserPostPassword("password");
 | 
							await h.needUserPostPassword("password");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// TODO : implement method
 | 
							await GroupsHelper.Delete(groupID);
 | 
				
			||||||
		h.error(500, "Method not implemented yet!");
 | 
					
 | 
				
			||||||
 | 
							h.success();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@ import { time } from "../utils/DateUtils";
 | 
				
			|||||||
import { GroupSettings } from "../entities/GroupSettings";
 | 
					import { GroupSettings } from "../entities/GroupSettings";
 | 
				
			||||||
import { existsSync, unlinkSync } from "fs";
 | 
					import { existsSync, unlinkSync } from "fs";
 | 
				
			||||||
import { PostsHelper } from "./PostsHelper";
 | 
					import { PostsHelper } from "./PostsHelper";
 | 
				
			||||||
 | 
					import { LikesHelper, LikesType } from "./LikesHelper";
 | 
				
			||||||
 | 
					import { NotificationsHelper } from "./NotificationsHelper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Groups helper
 | 
					 * Groups helper
 | 
				
			||||||
@@ -585,6 +587,28 @@ export class GroupsHelper {
 | 
				
			|||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Permanently delete a group
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param groupID Target group ID
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static async Delete(groupID: number) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete all likes of the group
 | 
				
			||||||
 | 
							await LikesHelper.DeleteAll(groupID, LikesType.GROUP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete the logo of the group
 | 
				
			||||||
 | 
							await this.DeleteLogo(groupID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete all group posts
 | 
				
			||||||
 | 
							await PostsHelper.DeleteAllGroup(groupID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Delete all group related notifications
 | 
				
			||||||
 | 
							await NotificationsHelper.DeleteAllRelatedWithGroup(groupID);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// TODO : continue deletion
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Turn a database row into a {GroupInfo} object
 | 
						 * Turn a database row into a {GroupInfo} object
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -266,6 +266,22 @@ export class NotificationsHelper {
 | 
				
			|||||||
		}));
 | 
							}));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete all the notifications related with a group
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param groupID Target group ID
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static async DeleteAllRelatedWithGroup(groupID: number) {
 | 
				
			||||||
 | 
							const n = new Notif({
 | 
				
			||||||
 | 
								onElemType: NotifElemType.GROUP_MEMBERSHIP,
 | 
				
			||||||
 | 
								onElemID: groupID
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							await this.Delete(n);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							n.onElemType = NotifElemType.GROUP_PAGE;
 | 
				
			||||||
 | 
							await this.Delete(n);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Count the number of unread notifications of a user
 | 
						 * Count the number of unread notifications of a user
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -358,6 +358,22 @@ export class PostsHelper {
 | 
				
			|||||||
		return list.map((l) => this.DBToPost(l));
 | 
							return list.map((l) => this.DBToPost(l));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete all the posts of a given group
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param groupID Target group ID
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static async ExportAllPostsGroup(groupID: number) : Promise<Post[]> {
 | 
				
			||||||
 | 
							const list = await DatabaseHelper.Query({
 | 
				
			||||||
 | 
								table: TABLE_NAME,
 | 
				
			||||||
 | 
								where: {
 | 
				
			||||||
 | 
									group_id: groupID
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return list.map((l) => this.DBToPost(l));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the access level of a user over a post
 | 
						 * Get the access level of a user over a post
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
@@ -534,6 +550,16 @@ export class PostsHelper {
 | 
				
			|||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete all the posts of a given group
 | 
				
			||||||
 | 
						 * 
 | 
				
			||||||
 | 
						 * @param groupID Target group ID
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static async DeleteAllGroup(groupID: number) {
 | 
				
			||||||
 | 
							for(const post of await this.ExportAllPostsGroup(groupID))
 | 
				
			||||||
 | 
								await this.Delete(post.id);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Turn a database entry into a row object
 | 
						 * Turn a database entry into a row object
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user