From 9f22f2df5679d296c8fe2cd09f5f95cdf81ee891 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 20 Mar 2020 18:34:28 +0100 Subject: [PATCH] Can change post visibility level --- src/controllers/PostsController.ts | 5 ++++- src/helpers/PostsHelper.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index d6bcd60..568e439 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -305,7 +305,10 @@ export class PostsController { */ public static async SetVisibilityLevel(h: RequestHandler) { - // TODO : implement + const postID = await h.postPostIDWithAccess("postID", PostAccessLevel.FULL_ACCESS); + const newVisibility = this.PostVisibilityLevel(h, "new_level"); + + await PostsHelper.SetLevel(postID, newVisibility); h.success(""); } diff --git a/src/helpers/PostsHelper.ts b/src/helpers/PostsHelper.ts index 83bc805..619a8b2 100644 --- a/src/helpers/PostsHelper.ts +++ b/src/helpers/PostsHelper.ts @@ -442,6 +442,24 @@ export class PostsHelper { }) > 0; } + /** + * Set new visibility level to the post + * + * @param postID Target post ID + * @param level Target access level + */ + public static async SetLevel(postID: number, level: PostVisibilityLevel) { + await DatabaseHelper.UpdateRows({ + table: TABLE_NAME, + where: { + ID: postID + }, + set: { + niveau_visibilite: level + } + }) + } + /** * Turn a database entry into a row object *