summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorrohan09-raj <rajrohan1914@gmail.com>2022-08-14 00:19:58 +0530
committerrohan09-raj <rajrohan1914@gmail.com>2022-08-14 00:19:58 +0530
commit4e99bfe1878620769d48532b182692e51c7266ef (patch)
treec3b02c73fd5f9fba85461e00db9905ee1371a8a0 /server
parent3673947d4905948de2e466a813019b1de9629bd2 (diff)
admin panel and api integration
Diffstat (limited to 'server')
-rw-r--r--server/controllers/users.js48
-rw-r--r--server/routes/users.js3
2 files changed, 40 insertions, 11 deletions
diff --git a/server/controllers/users.js b/server/controllers/users.js
index 672e422..3dfed14 100644
--- a/server/controllers/users.js
+++ b/server/controllers/users.js
@@ -1,4 +1,3 @@
-import mongoose from 'mongoose';
import UserDetails from '../models/users';
import sendOTP from '../services/twilio';
@@ -19,12 +18,10 @@ const createUser = async (req, res) => {
try {
const existingUser = await UserDetails.findOne({name, mobile, email});
if (existingUser) {
- sendOTP('+919696712475', 'Hi, I am Rohan Raj Gupta');
+ // sendOTP('+919696712475', 'Hi, I am Rohan Raj Gupta');
return res.status(400).json({message: 'User already exists.'});
}
- console.log(req.body);
-
const result = await UserDetails.create({
indianResident,
name,
@@ -36,14 +33,11 @@ const createUser = async (req, res) => {
photo,
documents,
biometrics,
- verified,
});
- console.log(result);
-
const aadhaarNumber = 281943258754;
- res.status(200).json({result, aadhaarNumber});
+ return res.status(200).json({result, aadhaarNumber});
} catch (error) {
res.status(500).json({message: 'Something went wrong.'});
}
@@ -64,7 +58,7 @@ const getVerifiedUsers = async (req, res) => {
try {
const verifiedUsers = await UserDetails.find({verified: true});
- res.status(200).json(verifiedUsers);
+ return res.status(200).json(verifiedUsers);
} catch (error) {
res.status(404).json({message: error.message});
}
@@ -76,10 +70,42 @@ const getUnverifiedUsers = async (req, res) => {
console.log(unverifiedUsers);
- res.status(200).json(unverifiedUsers);
+ return res.status(200).json(unverifiedUsers);
+ } catch (error) {
+ res.status(404).json({message: error.message});
+ }
+};
+
+const updateUser = async (req, res) => {
+ const {id} = req.params;
+
+ console.log(id, req.body);
+ try {
+ await UserDetails.findByIdAndUpdate(id, {$set: req.body}, {new: true});
+
+ res.status(200).json({message: 'User Updated Successfully'});
+ } catch (error) {
+ res.status(404).json({message: error.message});
+ }
+};
+
+const deleteUser = async (req, res) => {
+ const {id} = req.params;
+ try {
+ if (await UserDetails.findById(id)) {
+ const user = await UserDetails.findByIdAndDelete(id);
+ res.status(200).json({message: 'User Deleted Successfully'});
+ }
} catch (error) {
res.status(404).json({message: error.message});
}
};
-export default {createUser, getUser, getVerifiedUsers, getUnverifiedUsers};
+export default {
+ createUser,
+ getUser,
+ getVerifiedUsers,
+ getUnverifiedUsers,
+ updateUser,
+ deleteUser,
+};
diff --git a/server/routes/users.js b/server/routes/users.js
index 49c9fda..aba2caf 100644
--- a/server/routes/users.js
+++ b/server/routes/users.js
@@ -8,4 +8,7 @@ router.get('/user/:id', users.getUser);
router.get('/verifiedusers', users.getVerifiedUsers);
router.get('/unverifiedusers', users.getUnverifiedUsers);
+router.patch('/user/:id', users.updateUser);
+router.delete('/user/:id', users.deleteUser);
+
export default router;