From c34cd7f8094a4a2c605b4479807e7a9cfcf24b19 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 2 Nov 2024 22:15:24 +0300 Subject: [PATCH] added new endpoint --- src/controllers/group.js | 8 ++++++++ src/routers/group.js | 1 + 2 files changed, 9 insertions(+) diff --git a/src/controllers/group.js b/src/controllers/group.js index da439b5..d4cb0f8 100644 --- a/src/controllers/group.js +++ b/src/controllers/group.js @@ -49,6 +49,14 @@ class GroupController { return res.status(200).send(group["id"].toString()); } + async getById(req, res) { + let groupId = req.params.groupId; + + let groupName = (await GroupService.getById(groupId)).name; + + return res.status(200).send(groupName); + } + async getUsersInGroup(req, res) { const groupId = req.params.groupId; diff --git a/src/routers/group.js b/src/routers/group.js index 8de36dc..6cedaf9 100644 --- a/src/routers/group.js +++ b/src/routers/group.js @@ -10,5 +10,6 @@ GroupRouter.post('/create/:groupName', tryHandler(auth.authenticate), tryHandler GroupRouter.post('/join/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.requirePassword), tryHandler(auth.checkGroupPassword), tryHandler(GroupController.join)); GroupRouter.post('/password/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.authorizeGroupOwner), tryHandler(auth.requirePassword), tryHandler(GroupController.updatePassword)); GroupRouter.get('/byName/:groupName', tryHandler(auth.authenticate), tryHandler(existance.groupNameExists), tryHandler(GroupController.getByName)) +GroupRouter.get('/byId/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getById)) GroupRouter.get('/getUsers/:groupId', tryHandler(auth.authenticate), tryHandler(existance.groupExists), tryHandler(auth.userIsInGroup), tryHandler(GroupController.getUsersInGroup)) export default GroupRouter; \ No newline at end of file