summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaster4385 <venkateshchaturvedi12@gmail.com>2022-08-19 23:51:13 +0530
committerBlaster4385 <venkateshchaturvedi12@gmail.com>2022-08-19 23:51:13 +0530
commit856728cfae03da554d4db91b0635a53f1c9f915c (patch)
tree1ce1fa3561dc6935f4f3aab521773145cdd3f7ec
parent6c867e639e565262bbf71342f953456a7d0b7f7a (diff)
DeShit the api
-rw-r--r--client/src/pages/Enrollment/Enrollment.jsx18
-rw-r--r--client/src/services/apiservice.js5
-rw-r--r--server/controllers/message.js29
-rw-r--r--server/controllers/otp.js17
-rw-r--r--server/index.js4
-rw-r--r--server/routes/message.js9
-rw-r--r--server/routes/otp.js8
-rw-r--r--server/services/twilio.js4
8 files changed, 59 insertions, 35 deletions
diff --git a/client/src/pages/Enrollment/Enrollment.jsx b/client/src/pages/Enrollment/Enrollment.jsx
index f180667..e0cfd84 100644
--- a/client/src/pages/Enrollment/Enrollment.jsx
+++ b/client/src/pages/Enrollment/Enrollment.jsx
@@ -33,7 +33,9 @@ const Enrollment = () => {
const navigate = useNavigate()
const [unverified, setUnverified] = useState(true)
- const { mutate } = useMutation((payload) => createUser(payload))
+ const pushUser = useMutation((payload) => createUser(payload))
+
+ // const setConfirm = useMutation((payload) => sendMessage(payload))
const handleSubmit = () => {
if (page === 0) {
@@ -107,9 +109,7 @@ const Enrollment = () => {
} else if (page === 6) {
setPage(page + 1)
} else if (page === 7) {
- setPage(page + 1)
- } else if (page === 8) {
- mutate(
+ pushUser.mutate(
{
indianResident: userData.indianResident,
name: userData.name,
@@ -127,11 +127,17 @@ const Enrollment = () => {
},
{
onSuccess: () => {
- setUserData(initialUserData)
- navigate('/')
+ // setConfirm.mutate({
+ // mobile: `+91${userData.mobile}`,
+ // id: pushUser.data._id
+ // })
+ setPage(page + 1)
}
}
)
+ } else if (page === 8) {
+ setUserData(initialUserData)
+ navigate('/')
}
}
diff --git a/client/src/services/apiservice.js b/client/src/services/apiservice.js
index 0aa9337..e989c01 100644
--- a/client/src/services/apiservice.js
+++ b/client/src/services/apiservice.js
@@ -23,3 +23,8 @@ export const sendOTP = async (payload) => {
const response = await apiClient.post('/otp', payload)
return response
}
+
+export const sendMessage = async (payload) => {
+ const response = await apiClient.post('/message', payload)
+ return response
+}
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;