diff --git a/controller/adminController.js b/controller/adminController.js index 61a0ebd..48c6a3f 100644 --- a/controller/adminController.js +++ b/controller/adminController.js @@ -410,28 +410,28 @@ const highestDonor = async (req, res, next) => { } }; -// const create = async (req,res,next) => { -// try { -// const {uname,password} = req.body; -// if(!uname||!password) -// return next(new ErrorHandler(406,"All input fields required -> uname,password")) -// const encryptedPassword = await bcrypt.hash(password, 12); -// const admin = await Admin.create({ -// uname, -// password:encryptedPassword -// }); -// if(admin) -// return res.status(200).json({success:true,msg:`Admin created : ${admin.uname}`}); -// } catch (err) { -// return next(err); -// } -// } +const create = async (req,res,next) => { + try { + const {uname,password} = req.body; + if(!uname||!password) + return next(new ErrorHandler(406,"All input fields required -> uname,password")) + const encryptedPassword = await bcrypt.hash(password, 12); + const admin = await Admin.create({ + uname, + password:encryptedPassword + }); + if(admin) + return res.status(200).json({success:true,msg:`Admin created : ${admin.uname}`}); + } catch (err) { + return next(err); + } +} module.exports = { refreshToken, login, itemlist, - // create, + create, changeStatus, toggleCollector, seeAllUsers, diff --git a/routes/adminRoutes.js b/routes/adminRoutes.js index 6f22620..012ec7e 100644 --- a/routes/adminRoutes.js +++ b/routes/adminRoutes.js @@ -12,6 +12,8 @@ router.patch('/status/:itemId',authverify.adminauth,adminController.changeStatus router.patch('/donate/:itemId',authverify.adminauth,adminController.donateItem); router.post('/refresh',adminController.refreshToken); router.post('/login',adminController.login); + +//This route is for testing purposes only // router.post('/create',adminController.create);