1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 06:49:23 +00:00

Start group deletion

This commit is contained in:
Pierre HUBERT 2020-03-26 16:37:40 +01:00
parent 21a5e0df2e
commit 7375152fcf
4 changed files with 69 additions and 2 deletions

View File

@ -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();
} }
/** /**

View File

@ -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
* *

View File

@ -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
* *

View File

@ -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
* *