From b5f78bf3049c181b47d8692b728d7087c4fad51d Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 27 Apr 2025 22:58:24 +0530 Subject: Bug Fix: preventing an undefined friendId causing unwanted deletion of all of the user's friendships (one sidedly, too\!) --- src/controller/friend.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/controller/friend.ts') diff --git a/src/controller/friend.ts b/src/controller/friend.ts index 5d76350..4690f39 100644 --- a/src/controller/friend.ts +++ b/src/controller/friend.ts @@ -87,9 +87,11 @@ const addFriend = async (req: Request, res: Response) => { const removeFriend = async (req: Request, res: Response) => { try { + if (req.body.friendId === undefined || req.body.friendId === null || !Number.isInteger(req.body.friendId)) { + res.status(400).json({ message: "Invalid Friend ID" }); // @ts-ignore - if (req.userId == req.body.friendId) { - res.status(400).json({ message: "Attempted to unfriend self" }); + } else if (req.userId == req.body.friendId) { + res.status(400).json({message: "Attempted to unfriend self"}); } else { // @ts-ignore const { count } = await unfriend(req.userId, req.body.friendId) -- cgit v1.2.3