1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can set for friends if they can create posts or not

This commit is contained in:
Pierre HUBERT 2020-01-01 15:08:15 +01:00
parent 4cfb85d1ad
commit bb47968626
3 changed files with 36 additions and 0 deletions

View File

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

View File

@ -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)},

View File

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