Skip to content

Commit 6602931

Browse files
committed
feat(routes): add remove user from congregation for admin
1 parent f300a69 commit 6602931

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/v3/controllers/admin_controller.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,42 @@ export const congregationResetSpeakersKey = async (req: Request, res: Response)
833833
res.locals.message = `admin reset the congregation speakers key`;
834834
res.status(200).json(result);
835835
};
836+
837+
export const userRemoveCongregation = async (req: Request, res: Response) => {
838+
const { id } = req.params;
839+
840+
if (!id || id === 'undefined') {
841+
res.locals.type = 'warn';
842+
res.locals.message = 'the user request id params is undefined';
843+
res.status(400).json({ message: 'REQUEST_ID_INVALID' });
844+
845+
return;
846+
}
847+
848+
const user = UsersList.findById(id);
849+
850+
if (!user) {
851+
res.locals.type = 'warn';
852+
res.locals.message = 'no user could not be found with the provided id';
853+
res.status(404).json({ message: 'USER_NOT_FOUND' });
854+
return;
855+
}
856+
857+
const userCong = user.profile.congregation?.id;
858+
859+
await user.removeCongregation();
860+
861+
if (userCong) {
862+
const cong = CongregationsList.findById(userCong);
863+
864+
if (cong) {
865+
cong.reloadMembers();
866+
}
867+
}
868+
869+
const result = await adminUsersGet(req.signedCookies.visitorid);
870+
871+
res.locals.type = 'info';
872+
res.locals.message = 'admin removed a user from a congregation';
873+
res.status(200).json(result);
874+
};

src/v3/routes/admin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
userDelete,
2424
userDisable2FA,
2525
userFlagToggle,
26+
userRemoveCongregation,
2627
userRevokeToken,
2728
userSessionDelete,
2829
usersGetAll,
@@ -97,6 +98,9 @@ router.patch('/users/:id/feature-flags', body('flagid').isString(), userFlagTogg
9798
// delete user session
9899
router.delete('/users/:id/sessions', body('identifiers').isArray(), userSessionDelete);
99100

101+
// remove user congregation
102+
router.delete('/users/:id/congregation', userRemoveCongregation);
103+
100104
// delete an user
101105
router.delete('/users/:id', userDelete);
102106

0 commit comments

Comments
 (0)