mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-28 14:38:52 +00:00
Can update following status of a frienship
This commit is contained in:
parent
f46d87def5
commit
4cfb85d1ad
@ -158,7 +158,7 @@ export class FriendsController {
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async RemoveFriend(h: RequestHandler) {
|
||||
const friendID = await h.postUserId("friendID");
|
||||
const friendID = await h.postFriendId("friendID");
|
||||
|
||||
await FriendsHelper.RemoveFriendship(h.getUserId(), friendID);
|
||||
|
||||
@ -167,6 +167,20 @@ export class FriendsController {
|
||||
h.success("The friend was removed from the list!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update following status of a friendship
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async SetFollowing(h: RequestHandler) {
|
||||
const friendID = await h.postFriendId("friendID");
|
||||
const follow = h.postBool("follow");
|
||||
|
||||
await FriendsHelper.SetFollowing(h.getUserId(), friendID, follow);
|
||||
|
||||
h.success("Following status upated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a friend object into an API entry
|
||||
*
|
||||
|
@ -91,6 +91,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/friends/remove", cb: (h) => FriendsController.RemoveFriend(h)},
|
||||
|
||||
{path: "/friends/setFollowing", cb: (h) => FriendsController.SetFollowing(h)},
|
||||
|
||||
|
||||
// Conversations controller
|
||||
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
||||
|
@ -10,6 +10,7 @@ import { UserHelper } from "../helpers/UserHelper";
|
||||
import { GroupsAccessLevel } from "./Group";
|
||||
import { GroupsHelper } from "../helpers/GroupsHelper";
|
||||
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||
|
||||
/**
|
||||
* Response to a request
|
||||
@ -209,6 +210,20 @@ export class RequestHandler {
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a friend included in a POST request
|
||||
*
|
||||
* @param name Name of the POST field
|
||||
*/
|
||||
public async postFriendId(name: string) : Promise<number> {
|
||||
const friendID = await this.postUserId(name);
|
||||
|
||||
if(!await FriendsHelper.AreFriend(this.getUserId(), friendID))
|
||||
this.error(401, "You are not friend with this personn!");
|
||||
|
||||
return friendID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find user ID based on its email address, included in a POST request
|
||||
*
|
||||
|
@ -227,6 +227,26 @@ export class FriendsHelper {
|
||||
}) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the following status for a friendship
|
||||
*
|
||||
* @param userID The ID of the user updating the status
|
||||
* @param friendID The ID of the target friend
|
||||
* @param follow New following status
|
||||
*/
|
||||
public static async SetFollowing(userID: number, friendID: number, follow: boolean) {
|
||||
await DatabaseHelper.UpdateRows({
|
||||
table: FRIENDS_TABLE,
|
||||
where: {
|
||||
ID_personne: userID,
|
||||
ID_amis: friendID
|
||||
},
|
||||
set: {
|
||||
abonnement: follow ? 1 : 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a user is following a friend or not
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user