mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can delete information associated to a post
This commit is contained in:
parent
db9be6bb31
commit
a1613758e4
@ -73,6 +73,10 @@ export class PostFile implements PostFileBuilder {
|
|||||||
get url() : string {
|
get url() : string {
|
||||||
return pathUserData(this.path)
|
return pathUserData(this.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sysPath() : string {
|
||||||
|
return pathUserData(this.path, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PostLinkBuilder {
|
export interface PostLinkBuilder {
|
||||||
|
@ -7,6 +7,8 @@ import { GroupMembershipLevels } from "../entities/GroupMember";
|
|||||||
import { mysql_date } from "../utils/DateUtils";
|
import { mysql_date } from "../utils/DateUtils";
|
||||||
import { LikesHelper, LikesType } from "./LikesHelper";
|
import { LikesHelper, LikesType } from "./LikesHelper";
|
||||||
import { CommentsHelper } from "./CommentsHelper";
|
import { CommentsHelper } from "./CommentsHelper";
|
||||||
|
import { existsSync, unlinkSync } from "fs";
|
||||||
|
import { SurveyHelper } from "./SurveyHelper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts helper
|
* Posts helper
|
||||||
@ -493,7 +495,18 @@ export class PostsHelper {
|
|||||||
// Delete all the comments associated to the post
|
// Delete all the comments associated to the post
|
||||||
await CommentsHelper.DeleteAll(postID);
|
await CommentsHelper.DeleteAll(postID);
|
||||||
|
|
||||||
// TODO : continue deletion
|
// Delete associated file (if any)
|
||||||
|
if(post.kind == PostKind.POST_KIND_IMAGE
|
||||||
|
|| post.kind == PostKind.POST_KIND_PDF) {
|
||||||
|
if(existsSync(post.file.sysPath))
|
||||||
|
unlinkSync(post.file.sysPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete associated survey (if any)
|
||||||
|
if(post.kind == PostKind.POST_KIND_SURVEY) {
|
||||||
|
if(await SurveyHelper.Exists(postID))
|
||||||
|
await SurveyHelper.Delete(postID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,61 @@ export class SurveyHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check out whether a survey is associated to a post or not
|
||||||
|
*
|
||||||
|
* @param postID Target post ID
|
||||||
|
*/
|
||||||
|
public static async Exists(postID: number) : Promise<boolean> {
|
||||||
|
return await DatabaseHelper.Count({
|
||||||
|
table: SURVEY_INFO_TABLE,
|
||||||
|
where: {
|
||||||
|
ID_texte: postID
|
||||||
|
}
|
||||||
|
}) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the survey associated with a post
|
||||||
|
*
|
||||||
|
* @param postID Target post ID
|
||||||
|
*/
|
||||||
|
private static async GetID(postID: number) : Promise<number> {
|
||||||
|
const info = await DatabaseHelper.QueryRow({
|
||||||
|
table: SURVEY_INFO_TABLE,
|
||||||
|
where: {
|
||||||
|
ID_texte: postID
|
||||||
|
},
|
||||||
|
fields: ["ID"]
|
||||||
|
});
|
||||||
|
|
||||||
|
if(info == null)
|
||||||
|
throw new Error("Survey for post " + postID + " not found!");
|
||||||
|
|
||||||
|
return info.ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the survey associated to a post
|
||||||
|
*
|
||||||
|
* @param postID Target post ID
|
||||||
|
*/
|
||||||
|
public static async Delete(postID: number) {
|
||||||
|
const surveyID = await this.GetID(postID);
|
||||||
|
|
||||||
|
DatabaseHelper.DeleteRows(SURVEY_RESPONSE_TABLE, {
|
||||||
|
ID_sondage: surveyID
|
||||||
|
});
|
||||||
|
|
||||||
|
DatabaseHelper.DeleteRows(SURVEY_CHOICES_TABLE, {
|
||||||
|
ID_sondage: surveyID
|
||||||
|
});
|
||||||
|
|
||||||
|
DatabaseHelper.DeleteRows(SURVEY_INFO_TABLE, {
|
||||||
|
ID: surveyID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get information about the survey of a post
|
* Get information about the survey of a post
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user