diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/message.js | 24 | ||||
-rw-r--r-- | server/controllers/users.js | 52 |
2 files changed, 38 insertions, 38 deletions
diff --git a/server/controllers/message.js b/server/controllers/message.js index 8061c7a..120cb20 100644 --- a/server/controllers/message.js +++ b/server/controllers/message.js @@ -1,40 +1,40 @@ -import generateOTP from '../utils/otp'; -import sendSMS from '../services/twilio'; +import generateOTP from "../utils/otp.js"; +import sendSMS from "../services/twilio.js"; const sendOTP = async (req, res) => { - const {mobile} = req.body; + const { mobile } = req.body; try { const otp = generateOTP(); const message = `Your OTP for Aadhaar verification is : ${otp}`; sendSMS(mobile, message); - res.status(200).json({message: 'OTP sent successfully', otpCode: otp}); + res.status(200).json({ message: "OTP sent successfully", otpCode: otp }); } catch (error) { - res.status(404).json({message: error}); + res.status(404).json({ message: error }); } }; const sendMessage = async (req, res) => { - const {mobile, id} = req.body; + const { mobile, id } = req.body; try { const message = `Your request for aadhaar card has been successfully submitted. Please use the id: ${id} for future reference.`; sendSMS(mobile, message); - res.status(200).json({message: 'Message sent successfully'}); + res.status(200).json({ message: "Message sent successfully" }); } catch (error) { - res.status(404).json({message: error}); + res.status(404).json({ message: error }); } }; const sendMessages = async (req, res) => { - const {mobile, message} = req.body; + const { mobile, message } = req.body; try { sendSMS(mobile, message); - res.status(200).json({message: 'Message sent successfully'}); + res.status(200).json({ message: "Message sent successfully" }); } catch (error) { - res.status(404).json({message: error}); + res.status(404).json({ message: error }); } }; -export default {sendOTP, sendMessage, sendMessages}; +export default { sendOTP, sendMessage, sendMessages }; 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 }); } }; |