diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index e0a26b66..c2a6438c 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -101,6 +101,7 @@ exports.orderNow = async (req, reply) => { } } + const insertedagent = await agent.save(); return insertedagent; @@ -109,4 +110,81 @@ exports.orderNow = async (req, reply) => { } catch (err) { throw boom.boomify(err); } - }; \ No newline at end of file + }; + + exports.getactiveDeliveryboys = async (req, reply) => { + try { + await DeliveryBoy.find({supplierId: req.params.supplierId,status:"active"}) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + 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/controllers/userController.js b/src/controllers/userController.js index f2b00277..95e10cc8 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -11,6 +11,7 @@ const libphonenumberjs = require("libphonenumber-js"); const boom = require("boom"); // Get Data Models +const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier") const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('../models/User') //const User = require("../models/User"); @@ -400,7 +401,15 @@ exports.sendSms = async (request, reply) => { const mobile = request.body.mobileNumbers//'8341426949'; const message = `Welcome to Arminta !!! your OTP is ${code} please use it for login.`//`Welcome to Arminta !!! your OTP is ${code} please use it for login.`; - await User.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } }) + const user = await User.findOne({phone: mobile}) + const supplier = await Supplier.findOne({phone: mobile}) + if(user){ + await User.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } }) + } + if(supplier){ + await Supplier.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } }) + } + const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`; const options = { diff --git a/src/models/supplier.js b/src/models/supplier.js index b0cbd46a..e52d28b0 100644 --- a/src/models/supplier.js +++ b/src/models/supplier.js @@ -99,8 +99,10 @@ const supplierSchema = new mongoose.Schema( status: { type: String, default: "pending" }, timestamp: { type: Date, default: Date.now } }); + const deliveryBoySchema = new mongoose.Schema({ + supplierId:{ type: String, default: null }, name: { type: String, default: null }, phone: { type: String, default: null,unique:true }, alternativeContactNumber : { type : String,default: null }, @@ -109,7 +111,7 @@ const supplierSchema = new mongoose.Schema( state: { type: String, default: null }, zip: { type: String, default: null }, timestamp: { type: Date, default: Date.now }, - status: { type: String, default: "active" }, + status: { type: String, default: "Inactive" }, }); diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index 54867d71..2bc076b5 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -103,7 +103,58 @@ module.exports = function (fastify, opts, next) { handler: supplierOrderController.addDeliveryboy, }); + fastify.get("/api/getActiveDeliveryboys/:supplierId", { + schema: { + tags: ["Supplier"], + description: "This is for Get avtive delivery boys Data", + summary: "This is for to Get avtive delivery boys Data", + params: { + required: ["supplierId"], + type: "object", + properties: { + supplierId: { + type: "string", + description: "supplierId", + }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + 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(); } diff --git a/src/controllers/tankscontroller.js b/src/tankers.js similarity index 100% rename from src/controllers/tankscontroller.js rename to src/tankers.js