Skip to content

Commit

Permalink
fix(api): make names optional when updating user
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Jan 12, 2025
1 parent c063b0a commit f2d5e3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/v3/controllers/congregation_admin_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,16 @@ export const userDetailsUpdate = async (req: Request, res: Response) => {
return;
}

const { user_secret_code, cong_role, cong_person_uid, cong_person_delegates } = req.body;
const { user_secret_code, cong_role, cong_person_uid, cong_person_delegates, first_name, last_name } = req.body;

await foundUser.updateCongregationDetails(cong_role, cong_person_uid, cong_person_delegates, user_secret_code);

const profile = structuredClone(foundUser.profile);
profile.firstname = { value: first_name, updatedAt: new Date().toISOString() };
profile.lastname = { value: last_name, updatedAt: new Date().toISOString() };

await foundUser.updateProfile(profile);

res.locals.type = 'warn';
res.locals.message = 'congregation admin fetched all users';
res.status(200).json({ message: 'USER_UPDATED_SUCCESSFULLY' });
Expand Down
6 changes: 4 additions & 2 deletions src/v3/routes/congregation_admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ router.get('/:id/users', congregationGetUsers);
// create a new user
router.post(
'/:id/users',
body('user_firstname').notEmpty().isString(),
body('user_lastname').notEmpty().isString(),
body('user_firstname').isString(),
body('user_lastname').isString(),
body('user_id').notEmpty().isString(),
body('cong_role').notEmpty().isArray(),
body('cong_person_uid').notEmpty().isString(),
Expand All @@ -73,6 +73,8 @@ router.patch(
body('cong_role').notEmpty().isArray(),
body('cong_person_uid').notEmpty().isString(),
body('cong_person_delegates').notEmpty().isArray(),
body('first_name').isString(),
body('last_name').isString(),
userDetailsUpdate
);

Expand Down

0 comments on commit f2d5e3a

Please sign in to comment.