diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index 8d45dfda..c2a6438c 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -101,7 +101,7 @@ exports.orderNow = async (req, reply) => { } } - + const insertedagent = await agent.save(); return insertedagent; @@ -127,4 +127,64 @@ exports.orderNow = async (req, reply) => { throw boom.boomify(err); } }; + + +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); + } +}; + \ No newline at end of file diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index 118017e4..2bc076b5 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -128,6 +128,32 @@ module.exports = function (fastify, opts, next) { handler: supplierOrderController.getactiveDeliveryboys, }); + + 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();