diff options
Diffstat (limited to 'server/controllers/users.js')
-rw-r--r-- | server/controllers/users.js | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/server/controllers/users.js b/server/controllers/users.js index 0880657..23b5013 100644 --- a/server/controllers/users.js +++ b/server/controllers/users.js @@ -1,6 +1,6 @@ -import UserDetails from '../models/users'; -import sendSMS from '../services/twilio'; -import generateAadhaar from '../utils/aadhaar'; +import UserDetails from "../models/users.js"; +import sendSMS from "../services/twilio.js"; +import generateAadhaar from "../utils/aadhaar.js"; const createUser = async (req, res) => { const { @@ -17,9 +17,9 @@ const createUser = async (req, res) => { } = req.body; try { - const existingUser = await UserDetails.findOne({name, mobile, dob}); + const existingUser = await UserDetails.findOne({ name, mobile, dob }); if (existingUser) { - return res.status(400).json({message: 'User already exists.'}); + return res.status(400).json({ message: "User already exists." }); } const result = await UserDetails.create({ @@ -35,68 +35,68 @@ const createUser = async (req, res) => { biometrics, }); - return res.status(200).json({result}); + return res.status(200).json({ result }); } catch (error) { - res.status(500).json({message: error}); + res.status(500).json({ message: error }); } }; const getUser = async (req, res) => { - const {id} = req.params; + const { id } = req.params; try { const user = await UserDetails.findById(id); res.status(200).json(user); } catch (error) { - res.status(404).json({message: error}); + res.status(404).json({ message: error }); } }; const getUserByAadhaarNumber = async (req, res) => { - const {aadhaar} = req.params; + const { aadhaar } = req.params; const aadhaarNumber = Number(aadhaar); try { - const user = await UserDetails.findOne({aadhaarNumber}); + const user = await UserDetails.findOne({ aadhaarNumber }); res.status(200).json(user); } catch (error) { - res.status(404).json({message: error}); + res.status(404).json({ message: error }); } }; const getVerifiedUsers = async (req, res) => { try { - const verifiedUsers = await UserDetails.find({verified: true}); + const verifiedUsers = await UserDetails.find({ verified: true }); return res.status(200).json(verifiedUsers); } catch (error) { - res.status(404).json({message: error.message}); + res.status(404).json({ message: error.message }); } }; const getUnverifiedUsers = async (req, res) => { try { - const unverifiedUsers = await UserDetails.find({verified: false}); + const unverifiedUsers = await UserDetails.find({ verified: false }); console.log(unverifiedUsers); return res.status(200).json(unverifiedUsers); } catch (error) { - res.status(404).json({message: error.message}); + res.status(404).json({ message: error.message }); } }; const updateUser = async (req, res) => { - const {id} = req.params; + const { id } = req.params; try { const user = await UserDetails.findByIdAndUpdate( id, - {$set: req.body}, - {new: true} + { $set: req.body }, + { new: true } ); if (!user.aadhaarNumber) { await UserDetails.findByIdAndUpdate(id, { - $set: {aadhaarNumber: generateAadhaar()}, + $set: { aadhaarNumber: generateAadhaar() }, }); sendSMS( @@ -105,21 +105,21 @@ const updateUser = async (req, res) => { ); } - res.status(200).json({message: 'User Updated Successfully'}); + res.status(200).json({ message: "User Updated Successfully" }); } catch (error) { - res.status(404).json({message: error.message}); + res.status(404).json({ message: error.message }); } }; const deleteUser = async (req, res) => { - const {id} = req.params; + const { id } = req.params; try { if (await UserDetails.findById(id)) { const user = await UserDetails.findByIdAndDelete(id); - res.status(200).json({message: 'User Deleted Successfully'}); + res.status(200).json({ message: "User Deleted Successfully" }); } } catch (error) { - res.status(404).json({message: error.message}); + res.status(404).json({ message: error.message }); } }; @@ -131,7 +131,7 @@ const getUpdatingUsers = async (req, res) => { }); return res.status(200).json(updatingUsers); } catch (error) { - res.status(404).json({message: error.message}); + res.status(404).json({ message: error.message }); } }; |