mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Send (create) a friendship request
This commit is contained in:
parent
ca2e106852
commit
fed23994fa
@ -88,6 +88,33 @@ export class FriendsController {
|
|||||||
h.send(response);
|
h.send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a friendship request
|
||||||
|
*
|
||||||
|
* @param h Request handler
|
||||||
|
*/
|
||||||
|
public static async SendRequest(h: RequestHandler) {
|
||||||
|
const friendID = await h.postUserId("friendID");
|
||||||
|
|
||||||
|
if(friendID == h.getUserId())
|
||||||
|
h.error(401, "You can not become a friend of yourself!");
|
||||||
|
|
||||||
|
if(await FriendsHelper.AreFriend(h.getUserId(), friendID))
|
||||||
|
h.error(401, "You are already friend with this personn!");
|
||||||
|
|
||||||
|
// Check if a request is already in progress
|
||||||
|
if(await FriendsHelper.SentRequest(h.getUserId(), friendID)
|
||||||
|
|| await FriendsHelper.SentRequest(friendID, h.getUserId()))
|
||||||
|
h.error(401, "A friendship request is already in progress!");
|
||||||
|
|
||||||
|
// Send the request
|
||||||
|
await FriendsHelper.SendRequest(h.getUserId(), friendID);
|
||||||
|
|
||||||
|
// TODO : create the notification
|
||||||
|
|
||||||
|
h.success("Send (create) the friendship request");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn a friend object into an API entry
|
* Turn a friend object into an API entry
|
||||||
*
|
*
|
||||||
|
@ -83,6 +83,8 @@ export const Routes : Route[] = [
|
|||||||
|
|
||||||
{path: "/friends/getStatus", cb: (h) => FriendsController.GetStatus(h)},
|
{path: "/friends/getStatus", cb: (h) => FriendsController.GetStatus(h)},
|
||||||
|
|
||||||
|
{path: "/friends/sendRequest", cb: (h) => FriendsController.SendRequest(h)},
|
||||||
|
|
||||||
|
|
||||||
// Conversations controller
|
// Conversations controller
|
||||||
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
{path: "/conversations/create", cb: (h) => ConversationsController.CreateConversation(h)},
|
||||||
|
@ -80,6 +80,23 @@ export class FriendsHelper {
|
|||||||
return this.DbToFriend(result);
|
return this.DbToFriend(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send (create) a new membership request
|
||||||
|
*
|
||||||
|
* @param userID The user sending the request
|
||||||
|
* @param targetUser The ID of the target user
|
||||||
|
*/
|
||||||
|
public static async SendRequest(userID: number, targetUser: number) {
|
||||||
|
await DatabaseHelper.InsertRow(
|
||||||
|
FRIENDS_TABLE,
|
||||||
|
{
|
||||||
|
ID_personne: targetUser,
|
||||||
|
ID_amis: userID,
|
||||||
|
actif: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check out whether a user sent a request to another friend
|
* Check out whether a user sent a request to another friend
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user