From 03b88ccc8db4afa345b8d5f4219615d1fc23ead6 Mon Sep 17 00:00:00 2001 From: hardcodder Date: Fri, 2 Apr 2021 14:06:16 +0530 Subject: [PATCH] Added deleteUser Route --- controllers/profile.js | 19 +++++++++++++++++++ routes/profile.js | 2 ++ 2 files changed, 21 insertions(+) diff --git a/controllers/profile.js b/controllers/profile.js index 479076e..71839ea 100644 --- a/controllers/profile.js +++ b/controllers/profile.js @@ -83,4 +83,23 @@ module.exports.postProfile = async (req , res , next) => { error:err }) ; } +} + +module.exports.deleteUser = async (req , res , next) => { + const userId = req.user._id ; + try + { + await Student.deleteOne({user:userId}) ; + await User.deleteOne({_id : userId}) ; + res.json({ + message:"Successfully deleted" + }) ; + } + catch(err) + { + console.log(err); + res.json({ + error:err + }) ; + } } \ No newline at end of file diff --git a/routes/profile.js b/routes/profile.js index 211a3be..d28c137 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -8,4 +8,6 @@ router.get('/getProfile' , authMiddleware , profileRoute.getProfile) ; router.post('/postProfile' , authMiddleware , profileRoute.postProfile) ; +router.post('/deleteUser' , authMiddleware , profileRoute.deleteUser) ; + module.exports = router ; \ No newline at end of file