made changes for sending otp to supplier

master
varun 3 years ago
parent abee47ecd4
commit 1b0fc4072c

@ -128,3 +128,63 @@ exports.orderNow = async (req, reply) => {
}
};
exports.verifyPhone = async (req, reply) => {
console.log("-------------------------------------------------");
try {
phone = req.body.phone;
phoneVerificationCode = req.body.phoneVerificationCode;
// check if user exists in the system. If user exists , display message that
// username is not available
console.log(
"this is the phone and verification code",
phone,
phoneVerificationCode
);
userExists = await Supplier.findOne({
phone: phone,
phoneVerified: false,
phoneVerificationCode: phoneVerificationCode,
});
console.log(userExists);
if (userExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
phoneVerificationCode: phoneVerificationCode,
};
const update = { phoneVerified: true };
const doc = await Supplier.findOneAndUpdate(filter, update);
updatedUser = await Supplier.findOne({ phone: phone });
if (updatedUser.phoneVerified) {
reply.send('{"armintatankdata":{"error":false,"verified": true}}');
} else {
error = {
armintatankdata: {
error: true,
code: 10005,
message: "10005 - Verification code entered cannot be validated.",
},
};
req.body.regError = error;
reply.send(error);
}
} else {
error = {
armintatankdata: {
error: true,
code: 10005,
message: "10005 - Verification code entered cannot be validated.",
},
};
req.body.regError = error;
reply.send(error);
}
} catch (err) {
throw boom.boomify(err);
}
};

@ -129,6 +129,32 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "POST",
url: "/api/phoneverify",
schema: {
tags: ["Supplier-Data"],
description: "This is for verify supplier Phone",
summary: "This is to Verify supplier Phone.",
body: {
type: "object",
required: ["phone"],
properties: {
phoneVerificationCode: { type: "string" },
phone: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler: supplierOrderController.verifyPhone,
});
next();
}

Loading…
Cancel
Save