supplier phone verifyApi

master
Bhaskara Kishore 3 years ago
parent a0a2114a36
commit 4844be2e7c

@ -144,7 +144,7 @@ exports.loginSupplier = async(request, reply) =>{
message: "Please Verify your phone number", message: "Please Verify your phone number",
}, },
}); });
} else if (!oneTimePasswordSetFlag) { } else if (oneTimePasswordSetFlag) {
reply.send({ reply.send({
simplydata: { simplydata: {
error: false, error: false,
@ -349,7 +349,7 @@ exports.validatePhoneFormat = async (req, reply) => {
code: 10002, code: 10002,
message: message:
"10002 - Phone # " + "10002 - Phone # " +
user.phone + supplier.phone +
" is not a valid phone number", " is not a valid phone number",
}, },
}; };
@ -463,3 +463,61 @@ exports.logoutsupplier = async (request, 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
);
supplierExists = await Supplier.findOne({
phone: phone,
phoneVerified: false,
phoneVerificationCode: phoneVerificationCode,
});
console.log(supplierExists);
if (supplierExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
phoneVerificationCode: phoneVerificationCode,
};
const update = { phoneVerified: true };
const doc = await Supplier.findOneAndUpdate(filter, update);
updatedSupplier = await Supplier.findOne({ phone: phone });
if (updatedSupplier.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);
}
};

@ -96,6 +96,33 @@ module.exports = function (fastify, opts, next) {
handler: supplierController.addSupplier, handler: supplierController.addSupplier,
}); });
fastify.route({
method: "POST",
url: "/api/supplierphone",
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: validationHandler.verifyPhone,
});
next(); next();
} }

Loading…
Cancel
Save