Skip to content

Commit 53a996d

Browse files
committed
feat(routes): add route to update congregation name and number
1 parent 8c00b92 commit 53a996d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/v3/controllers/admin_controller.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,50 @@ export const userRemoveCongregation = async (req: Request, res: Response) => {
878878
res.locals.message = 'admin removed a user from a congregation';
879879
res.status(200).json(result);
880880
};
881+
882+
export const updateBasicCongregationInfo = async (req: Request, res: Response) => {
883+
const errors = validationResult(req);
884+
885+
if (!errors.isEmpty()) {
886+
const msg = formatError(errors);
887+
888+
res.locals.type = 'warn';
889+
res.locals.message = `invalid input: ${msg}`;
890+
891+
res.status(400).json({ message: 'error_api_bad-request' });
892+
893+
return;
894+
}
895+
896+
const { id } = req.params;
897+
898+
if (!id || id === 'undefined') {
899+
res.locals.type = 'warn';
900+
res.locals.message = 'the congregation request id params is undefined';
901+
res.status(400).json({ message: 'REQUEST_ID_INVALID' });
902+
903+
return;
904+
}
905+
906+
const cong = CongregationsList.findById(id);
907+
908+
if (!cong) {
909+
res.locals.type = 'warn';
910+
res.locals.message = 'no congregation could not be found with the provided id';
911+
res.status(404).json({ message: 'CONGREGATION_NOT_FOUND' });
912+
return;
913+
}
914+
915+
const settings = structuredClone(cong.settings);
916+
917+
settings.cong_name = req.body.name as string;
918+
settings.cong_number = req.body.number as string;
919+
920+
await cong.saveSettings(settings);
921+
922+
const result = await adminCongregationsGet();
923+
924+
res.locals.type = 'info';
925+
res.locals.message = `admin update basic info for congregation ${id}`;
926+
res.status(200).json(result);
927+
};

src/v3/routes/admin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
flagUpdate,
2020
getAllCongregations,
2121
logoutAdmin,
22+
updateBasicCongregationInfo,
2223
userAssignCongregation,
2324
userDelete,
2425
userDisable2FA,
@@ -64,6 +65,14 @@ router.patch('/congregations/:id/feature-flags', body('flagid').isString(), cong
6465
// toggle data sync
6566
router.patch('/congregations/:id/data-sync', congregationDataSyncToggle);
6667

68+
// update congregation name and number
69+
router.patch(
70+
'/congregations/:id',
71+
body('name').notEmpty().isString(),
72+
body('number').notEmpty().isString(),
73+
updateBasicCongregationInfo
74+
);
75+
6776
// reset speakers key
6877
router.delete('/congregations/:id/speakers-key', congregationResetSpeakersKey);
6978

0 commit comments

Comments
 (0)