From bb47968626df393c70c0bfe66701f4a7ddf7ce5a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 1 Jan 2020 15:08:15 +0100 Subject: [PATCH] Can set for friends if they can create posts or not --- src/controllers/FriendsController.ts | 14 ++++++++++++++ src/controllers/Routes.ts | 2 ++ src/helpers/FriendsHelper.ts | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/controllers/FriendsController.ts b/src/controllers/FriendsController.ts index d2d1033..aeaf33d 100644 --- a/src/controllers/FriendsController.ts +++ b/src/controllers/FriendsController.ts @@ -181,6 +181,20 @@ export class FriendsController { h.success("Following status upated!"); } + /** + * Update post text authorization status + * + * @param h Request handler + */ + public static async SetCanPostTexts(h: RequestHandler) { + const friendID = await h.postFriendId("friendID"); + const allow = h.postBool("allow"); + + await FriendsHelper.SetCanPostTexts(h.getUserId(), friendID, allow); + + h.success("Updated status!"); + } + /** * Turn a friend object into an API entry * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index 3bfc6b7..db2968d 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -93,6 +93,8 @@ export const Routes : Route[] = [ {path: "/friends/setFollowing", cb: (h) => FriendsController.SetFollowing(h)}, + {path: "/friends/set_can_post_texts", cb: (h) => FriendsController.SetCanPostTexts(h)}, + // Conversations controller {path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)}, diff --git a/src/helpers/FriendsHelper.ts b/src/helpers/FriendsHelper.ts index d9a90bd..d4681c0 100644 --- a/src/helpers/FriendsHelper.ts +++ b/src/helpers/FriendsHelper.ts @@ -265,6 +265,26 @@ export class FriendsHelper { }) > 0; } + /** + * Update the post creation authorization status + * + * @param userID The ID of the user updating the authorization status + * @param friendID The ID of the target friend + * @param allow New authorization status + */ + public static async SetCanPostTexts(userID: number, friendID: number, allow: boolean) { + await DatabaseHelper.UpdateRows({ + table: FRIENDS_TABLE, + where: { + ID_personne: userID, + ID_amis: friendID + }, + set: { + autoriser_post_page: allow ? 1 : 0 + } + }); + } + /** * Check out whether friendship allows to create posts or not *