diff options
author | Blaster4385 <venkateshchaturvedi12@gmail.com> | 2022-08-19 23:51:13 +0530 |
---|---|---|
committer | Blaster4385 <venkateshchaturvedi12@gmail.com> | 2022-08-19 23:51:13 +0530 |
commit | 856728cfae03da554d4db91b0635a53f1c9f915c (patch) | |
tree | 1ce1fa3561dc6935f4f3aab521773145cdd3f7ec /server | |
parent | 6c867e639e565262bbf71342f953456a7d0b7f7a (diff) |
DeShit the api
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/message.js | 29 | ||||
-rw-r--r-- | server/controllers/otp.js | 17 | ||||
-rw-r--r-- | server/index.js | 4 | ||||
-rw-r--r-- | server/routes/message.js | 9 | ||||
-rw-r--r-- | server/routes/otp.js | 8 | ||||
-rw-r--r-- | server/services/twilio.js | 4 |
6 files changed, 42 insertions, 29 deletions
diff --git a/server/controllers/message.js b/server/controllers/message.js new file mode 100644 index 0000000..efba38b --- /dev/null +++ b/server/controllers/message.js @@ -0,0 +1,29 @@ +import generateOTP from '../utils/otp'; +import sendSMS from '../services/twilio'; + +const sendOTP = async (req, res) => { + 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}); + } catch (error) { + res.status(404).json({message: error}); + } +}; + +const sendMessage = async (req, res) => { + 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'}); + } catch (error) { + res.status(404).json({message: error}); + } +}; + +export default {sendOTP, sendMessage};
\ No newline at end of file diff --git a/server/controllers/otp.js b/server/controllers/otp.js deleted file mode 100644 index 5b4bd82..0000000 --- a/server/controllers/otp.js +++ /dev/null @@ -1,17 +0,0 @@ -import generateOTP from '../utils/otp'; -import sendMessage from '../services/twilio'; - -const sendOTP = async (req, res) => { - const {mobile} = req.body; - - try { - const otp = generateOTP(); - const message = `Your OTP for Aadhaar verification is : ${otp}`; - sendMessage(mobile, message); - res.status(200).json({message: 'OTP sent successfully', otpCode: otp}); - } catch (error) { - res.status(404).json({message: error}); - } -}; - -export default {sendOTP}; diff --git a/server/index.js b/server/index.js index 2ccd121..2a1bb1b 100644 --- a/server/index.js +++ b/server/index.js @@ -6,7 +6,7 @@ import dotenv from 'dotenv'; import userRoutes from './routes/users.js'; import healthRoutes from './routes/health.js'; -import otpRoutes from './routes/otp.js'; +import messageRoutes from './routes/message.js'; const app = Express(); dotenv.config(); @@ -17,7 +17,7 @@ app.use(cors()); app.use('/', healthRoutes); app.use('/', userRoutes); -app.use('/', otpRoutes); +app.use('/', messageRoutes); const CONNECTION_URL = process.env.CONNECTION_URL; const PORT = process.env.PORT; diff --git a/server/routes/message.js b/server/routes/message.js new file mode 100644 index 0000000..0062838 --- /dev/null +++ b/server/routes/message.js @@ -0,0 +1,9 @@ +import Express from 'express'; +import message from '../controllers/message'; + +const router = Express.Router(); + +router.post('/otp', message.sendOTP); +router.post('/message', message.sendMessage); + +export default router; diff --git a/server/routes/otp.js b/server/routes/otp.js deleted file mode 100644 index b73240e..0000000 --- a/server/routes/otp.js +++ /dev/null @@ -1,8 +0,0 @@ -import Express from 'express'; -import otp from '../controllers/otp'; - -const router = Express.Router(); - -router.post('/otp', otp.sendOTP); - -export default router; diff --git a/server/services/twilio.js b/server/services/twilio.js index f95cc5f..69eac16 100644 --- a/server/services/twilio.js +++ b/server/services/twilio.js @@ -3,7 +3,7 @@ import twilio from 'twilio'; const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; -const sendMessage = (phone, message) => { +const sendSMS = (phone, message) => { const client = twilio(accountSid, authToken); client.messages .create({ @@ -14,4 +14,4 @@ const sendMessage = (phone, message) => { .then((message) => console.log(message.sid)); }; -export default sendMessage; +export default sendSMS; |