Skip to content

Commit

Permalink
🌿 Update admin (HITK-TECH-Community#800)
Browse files Browse the repository at this point in the history
* Update Admin

* update admin route with validation

* trying

* push-again

* tested route

* Update updateAdmin.js
  • Loading branch information
mayank-del authored May 14, 2022
1 parent 8778514 commit 4e1a9e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/app/routes/admin/@validationSchema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ const forgotPasswordSchema = Joi.object({
const resetPasswordSchema = Joi.object({
newPassword: Joi.string().required(),
});
const updateAdminSchema =Joi.object({
firstName:Joi.string(),
lastName:Joi.string(),
contact,
username:Joi.string(),
})

module.exports = {
postSuperAdminSchema,
Expand All @@ -50,4 +56,5 @@ module.exports = {
inviteAdminSchema,
forgotPasswordSchema,
resetPasswordSchema,
updateAdminSchema,
};
4 changes: 4 additions & 0 deletions backend/app/routes/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
inviteAdminSchema,
forgotPasswordSchema,
resetPasswordSchema,
updateAdminSchema,
} = require('./@validationSchema');
const createSuperAdmin = require('./createSuperAdmin');
const postSuperAdmin = require('./postSuperAdmin');
Expand All @@ -18,6 +19,7 @@ const inviteAdmin = require('./inviteAdmin');
const changePassword = require('./changePassword');
const forgotPassword = require('./forgotPassword');
const resetPassword = require('./resetPassword');
const updateAdmin = require('./updateAdmin');

router.get('/', validationMiddleware(getAdminsSchema, 'query'), authMiddleware, getAdmins);
router.get('/createSuperAdmin', createSuperAdmin);
Expand All @@ -29,5 +31,7 @@ router.post('/forgotpassword', validationMiddleware(forgotPasswordSchema), forgo
router.post('/resetpassword/:token', validationMiddleware(resetPasswordSchema), resetPassword);

router.put('/password', validationMiddleware(passwordChangeSchema), authMiddleware, changePassword);
router.put('/:id/:token', validationMiddleware(updateAdminSchema), updateAdmin);


module.exports = router;
18 changes: 18 additions & 0 deletions backend/app/routes/admin/updateAdmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Admin = require('../../models/Admin');

module.exports =async (req, res) => {

try {
const updatedAdmin = await Admin.findByIdAndUpdate(
req.params.id,
{
$set: req.body,
},
{ new: true }
);
res.status(200).json(updatedAdmin);
} catch (err) {
res.status(500).json(err);
}
res.send('Done');
};

0 comments on commit 4e1a9e7

Please sign in to comment.