mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-30 17:14:43 +00:00 
			
		
		
		
	Can cancel a frienship request
This commit is contained in:
		| @@ -115,6 +115,24 @@ export class FriendsController { | ||||
| 		h.success("Send (create) the friendship request"); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Cancel (remove) a friendship request | ||||
| 	 *  | ||||
| 	 * @param h Request handler | ||||
| 	 */ | ||||
| 	public static async CancelRequest(h: RequestHandler) { | ||||
| 		const friendID = await h.postUserId("friendID"); | ||||
|  | ||||
| 		if(!await FriendsHelper.SentRequest(h.getUserId(), friendID)) | ||||
| 			h.error(401, "No friendship request was sent to this user!"); | ||||
| 		 | ||||
| 		await FriendsHelper.RemoveRequest(h.getUserId(), friendID); | ||||
|  | ||||
| 		// TODO : delete any related notification | ||||
|  | ||||
| 		h.success("Friendship request removed!"); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Turn a friend object into an API entry | ||||
| 	 *  | ||||
|   | ||||
| @@ -85,6 +85,8 @@ export const Routes : Route[] = [ | ||||
|  | ||||
| 	{path: "/friends/sendRequest", cb: (h) => FriendsController.SendRequest(h)}, | ||||
|  | ||||
| 	{path: "/friends/removeRequest", cb: (h) => FriendsController.CancelRequest(h)}, | ||||
|  | ||||
|  | ||||
| 	// Conversations controller | ||||
| 	{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)}, | ||||
|   | ||||
| @@ -114,6 +114,23 @@ export class FriendsHelper { | ||||
| 		}) > 0; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Delete a previously sent friendship request | ||||
| 	 *  | ||||
| 	 * @param userID The ID of the user who have sent the request | ||||
| 	 * @param targetUser The ID of the target user | ||||
| 	 */ | ||||
| 	public static async RemoveRequest(userID: number, targetUser: number) { | ||||
| 		await DatabaseHelper.DeleteRows( | ||||
| 			FRIENDS_TABLE, | ||||
| 			{ | ||||
| 				ID_personne: targetUser, | ||||
| 				ID_amis: userID, | ||||
| 				actif: 0 | ||||
| 			} | ||||
| 		); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Count the number of friendship requests a user | ||||
| 	 * received | ||||
|   | ||||
		Reference in New Issue
	
	Block a user