diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index 47ab44478..7d0017944 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -974,6 +974,21 @@ const userProfileController = function (UserProfile, Project) { .catch((error) => res.status(500).send(error)); }; + const updateAllMembersTeamCode = async (req, res) => { + const canEditTeamCode = await hasPermission(req.body.requestor, 'editTeamCode'); + if (!canEditTeamCode) { + res.status(403).send('You are not authorized to edit team code.'); + return; + } + const { userIds, replaceCode } = req.body; + if (userIds === null || userIds.length <= 0 || replaceCode === undefined) { + return res.status(400).send({ error: 'Missing property or value' }); + } + return UserProfile.updateMany({ _id: { $in: userIds } }, { $set: { teamCode: replaceCode } }) + .then((result) => res.status(200).send({ isUpdated: result.nModified > 0 })) + .catch((error) => res.status(500).send(error)); + }; + const updatepassword = async function (req, res) { const { userId } = req.params; const { requestor } = req.body; @@ -1607,6 +1622,7 @@ const userProfileController = function (UserProfile, Project) { getUserById, getreportees, updateOneProperty, + updateAllMembersTeamCode, updatepassword, getUserName, getTeamMembersofUser, diff --git a/src/routes/userProfileRouter.js b/src/routes/userProfileRouter.js index 795f6cfa3..bf6f79237 100644 --- a/src/routes/userProfileRouter.js +++ b/src/routes/userProfileRouter.js @@ -84,6 +84,8 @@ const routes = function (userProfile, project) { userProfileRouter.route('/userProfile/:userId/property').patch(controller.updateOneProperty); + userProfileRouter.route('/AllTeamCodeChanges').patch(controller.updateAllMembersTeamCode); + userProfileRouter.route('/userProfile/:userId/updatePassword').patch(controller.updatepassword); userProfileRouter.route('/userProfile/:userId/resetPassword').patch(controller.resetPassword);