Skip to content

Commit

Permalink
Merge pull request #1034 from OneCommunityGlobal/Ramakrishna_Editall_…
Browse files Browse the repository at this point in the history
…TeamCode_Backend

Ramakrishna edit all team code at Once
  • Loading branch information
one-community authored Aug 19, 2024
2 parents e187e01 + 29e89f8 commit 1630c70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1607,6 +1622,7 @@ const userProfileController = function (UserProfile, Project) {
getUserById,
getreportees,
updateOneProperty,
updateAllMembersTeamCode,
updatepassword,
getUserName,
getTeamMembersofUser,
Expand Down
2 changes: 2 additions & 0 deletions src/routes/userProfileRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1630c70

Please sign in to comment.