diff --git a/backend-services/friend-service/src/Routes/RequestsRouter.ts b/backend-services/friend-service/src/Routes/RequestsRouter.ts index 44f447eb050a6d2cd0321ebbd572a95cc66d47b9..9e0f13e0aed2840135c8c0880453bb6e39aacfa4 100644 --- a/backend-services/friend-service/src/Routes/RequestsRouter.ts +++ b/backend-services/friend-service/src/Routes/RequestsRouter.ts @@ -11,13 +11,13 @@ const requestManager = new RequestManager(friendManager); * GET '/' * Returns a string */ -RequestRouter.get('/', async (req:CustomJWTRequest, res:Response): Promise<void> => { +RequestRouter.get('/', async (req:CustomJWTRequest, res:Response): Promise<Response> => { const {token} = req; return requestManager.GetRequests(token as string).then((result) => { - res.status(200).json({requests: result}) + return res.status(200).json({requests: result}) }).catch((error: Error) => { - res.status(401).json({error: error.message}) + return res.status(401).json({error: error.message}) }); }); @@ -47,14 +47,16 @@ RequestRouter.put('/accept', async (req:CustomJWTRequest, res:Response): Promise const {request_id} = req.body; const {token} = req; - await requestManager.GetSingleRequest(request_id).then(result => { + return await requestManager.GetSingleRequest(request_id).then(result => { if(result.TargetUser !== token){ - return res.status(400).json({error: "unauthorised"}) + throw new Error("Unauthorised") + } else { + return requestManager.AcceptRequest(request_id).then((result) => { + return res.sendStatus(200) + }).catch((error: Error) => { + return res.status(400).json({error: error.message}) + }) } - }) - - return requestManager.AcceptRequest(request_id).then((result) => { - return res.sendStatus(200) }).catch((error: Error) => { return res.status(400).json({error: error.message}) }) @@ -67,14 +69,16 @@ RequestRouter.put('/reject', async (req:CustomJWTRequest, res:Response): Promise const {request_id} = req.body; const {token} = req; - await requestManager.GetSingleRequest(request_id).then(result => { + return await requestManager.GetSingleRequest(request_id).then(result => { if(result.TargetUser !== token){ - return res.status(400).json({error: "unauthorised"}) + throw new Error("Unauthorised") + } else { + return requestManager.RejectRequest(request_id).then((result) => { + return res.sendStatus(200) + }).catch((error: Error) => { + return res.status(400).json({error: error.message}) + }) } - }) - - return requestManager.RejectRequest(request_id).then((result) => { - return res.sendStatus(200) }).catch((error: Error) => { return res.status(400).json({error: error.message}) })