mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Can respond to a friendship request
This commit is contained in:
		@@ -133,6 +133,25 @@ export class FriendsController {
 | 
			
		||||
		h.success("Friendship request removed!");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Respond to a friendship request
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param h Request handler
 | 
			
		||||
	 */
 | 
			
		||||
	public static async RespondRequest(h: RequestHandler) {
 | 
			
		||||
		const friendID = await h.postUserId("friendID");
 | 
			
		||||
		const accept = h.postBool("accept");
 | 
			
		||||
 | 
			
		||||
		if(!await FriendsHelper.SentRequest(friendID, h.getUserId()))
 | 
			
		||||
			h.error(401, "No friendship request was sent by this user!");
 | 
			
		||||
		
 | 
			
		||||
		await FriendsHelper.RespondRequest(h.getUserId(), friendID, accept);
 | 
			
		||||
 | 
			
		||||
		// TODO : create notification
 | 
			
		||||
		
 | 
			
		||||
		h.success("Response to the friendship request successfully saved!");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a friend object into an API entry
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -87,6 +87,8 @@ export const Routes : Route[] = [
 | 
			
		||||
 | 
			
		||||
	{path: "/friends/removeRequest", cb: (h) => FriendsController.CancelRequest(h)},
 | 
			
		||||
 | 
			
		||||
	{path: "/friends/respondRequest", cb: (h) => FriendsController.RespondRequest(h)},
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// Conversations controller
 | 
			
		||||
	{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
 | 
			
		||||
 
 | 
			
		||||
@@ -131,6 +131,36 @@ export class FriendsHelper {
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Respond to a friendship request
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param userID The ID of the user who respond to the request
 | 
			
		||||
	 * @param friendID The ID of the user who sent the request
 | 
			
		||||
	 * @param accept TRUE to accept / FALSE else
 | 
			
		||||
	 */
 | 
			
		||||
	public static async RespondRequest(userID: number, friendID: number, accept: boolean) : Promise<boolean> {
 | 
			
		||||
		
 | 
			
		||||
		// Delete the request
 | 
			
		||||
		await this.RemoveRequest(friendID, userID);
 | 
			
		||||
 | 
			
		||||
		// If the request was rejected
 | 
			
		||||
		if(!accept)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		// If the request was accepted
 | 
			
		||||
		await DatabaseHelper.InsertRow(FRIENDS_TABLE, {
 | 
			
		||||
			ID_personne: userID,
 | 
			
		||||
			ID_amis: friendID,
 | 
			
		||||
			actif: 1
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		await DatabaseHelper.InsertRow(FRIENDS_TABLE, {
 | 
			
		||||
			ID_personne: friendID,
 | 
			
		||||
			ID_amis: userID,
 | 
			
		||||
			actif: 1
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Count the number of friendship requests a user
 | 
			
		||||
	 * received
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user