created bookings of supplier and delivery boys

master
varun 3 years ago
commit 60bf11771a

@ -10,7 +10,7 @@ const saltRounds = 10;
//Get the data models
const { Supplier ,ProfilePicture, generateSupplierId} = require('../models/supplier');
const { Supplier ,ProfilePicture, generateSupplierId, DeliveryBoy} = require('../models/supplier');
async function bcryptPassword(password) {
@ -55,6 +55,29 @@ exports.loginSupplier = async (req) => {
//DeliveryBoy Login Controller
exports.loginDeliveryBoy = async (req) => {
try {
const phone = req.body.phone;
const delivery = await DeliveryBoy.findOne({ phone: phone });
if (delivery) {
return { same: true, delivery: delivery };
} else {
return { same: false };
}
} catch (err) {
throw boom.boomify(err);
}
};
exports.addSupplier = async (req, reply) => {
try {
// await resetCounter();//to set customer id back to 0

@ -592,12 +592,10 @@ exports.deliveryboystart = async (req, reply) => {
try {
//let start_time,stop_time
const customerId = req.params.customerId;
const tankLocation = req.body.tankLocation;
const action = req.body.action
const receiver_tank = req.body.tankname
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:(req.body.to_type).toLowerCase()});
const receiver_tank_info = await Tank.findOne({ customerId ,tankName:receiver_tank,tankLocation:tankLocation.toLowerCase()});
const receiver_capacity = parseInt((receiver_tank_info.capacity).replace(/,/g, ''), 10)
const desired_water_percentage = parseInt((req.body.percentage).replace(/,/g, ''), 10)
const intervals = {};

@ -403,12 +403,16 @@ exports.sendSms = async (request, reply) => {
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.`;
const user = await User.findOne({phone: mobile})
const supplier = await Supplier.findOne({phone: mobile})
const deliveryBoy = await DeliveryBoy.findOne( { phone : mobile})
if(user){
await User.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } })
}
if(supplier){
await Supplier.findOneAndUpdate({phone: mobile}, { $set: {'phoneVerificationCode': code } })
}
if(deliveryBoy){
await DeliveryBoy.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)}`;

@ -1,7 +1,7 @@
//Get the data models
const { Supplier } = require('../models/supplier');
const { Supplier, DeliveryBoy } = require('../models/supplier');
const { FriendRequest } = require('../models/supplier')
const { ProfilePicture } = require('../models/User')
const { ProfilePicture, User } = require('../models/User')
const supplierController = require("../controllers/supplierController");
const customJwtAuth = require("../customAuthJwt");
const fastify = require("fastify")({
@ -235,6 +235,114 @@ exports.loginSupplier = async(request, reply) =>{
}
//Login Delivery Handler
exports.loginDeliveryBoy = async(request, reply) =>{
loginObject = await supplierController.loginDeliveryBoy(request);
console.log("loginObject...",loginObject)
if (loginObject.same) {
const phoneVerified = loginObject.delivery.phoneVerified;
const oneTimePasswordSetFlag = loginObject.delivery.oneTimePasswordSetFlag;
console.log(
"oneTimePasswordSetFlag is ......",
oneTimePasswordSetFlag,
typeof oneTimePasswordSetFlag,
typeof phoneVerified
);
if (!phoneVerified) {
reply.send({
simplydata: {
error: false,
phoneVerified: false,
phone: loginObject.delivery.phone,
oneTimePasswordSetFlag: oneTimePasswordSetFlag,
message: "Please Verify your phone number",
},
});
} else if (oneTimePasswordSetFlag) {
reply.send({
simplydata: {
error: false,
phoneVerified: phoneVerified,
phone: loginObject.delivery.phone,
oneTimePasswordSetFlag: true,
message: "Password must be reset",
},
});
} else {
const token = fastify.jwt.sign(
{
deliveryBoyname: loginObject.delivery.name,
deliveryBoyId: loginObject.delivery._id,
},
//expiresIn: expressed in seconds or a string describing a time span zeit/ms. Eg: 60, "2 days", "10h", "7d".
//A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc),
//otherwise milliseconds unit is used by default ("120" is equal to "120ms").
{ expiresIn: "30d" }
);
console.log(token, "..token")
var d_id = loginObject.delivery._id
console.log(d_id,"deliveryId")
var profilePicture = await ProfilePicture.findOne({ deliveryBoyId:d_id});
// request.session.set('supplierId', loginObject.supplier._id)
if (!profilePicture) {
reply.send({
simplydata: {
error: false,
apiversion: fastify.config.APIVERSION,
access_token: token,
phone: loginObject.delivery.phone,
deliveryBoyId: loginObject.delivery.deliveryBoyId,
deliveryBoyname: loginObject.delivery.name,
address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
},
});
}if (profilePicture) {
reply.send({
simplydata: {
error: false,
apiversion: fastify.config.APIVERSION,
access_token: token,
picture:profilePicture.picture,
phone: loginObject.delivery.phone,
deliveryBoyId: loginObject.delivery.deliveryBoyId,
deliveryBoyname: loginObject.delivery.name,
address: loginObject.delivery.address,
phoneVerified: loginObject.delivery.phoneVerified,
oneTimePasswordSetFlag: loginObject.delivery.oneTimePasswordSetFlag,
},
});
}
}
} else {
error = {
simplydata: {
error: true,
code: 400,
message: "Invalid Details",
},
};
reply.send(error);
}
}
// Check if all the required fields are supplied by the user
exports.fieldCheck = async (req, reply) => {
@ -527,6 +635,102 @@ exports.logoutsupplier = async (request, reply) => {
};
exports.deliveryBoyVerifyPhone = 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
);
deliveryBoyExists = await DeliveryBoy.findOne({
phone: phone,
phoneVerified: false,
phoneVerificationCode: phoneVerificationCode,
});
console.log(deliveryBoyExists);
if (deliveryBoyExists) {
// update the phoneVerified flag to true.
const filter = {
phone: phone,
phoneVerificationCode: phoneVerificationCode,
};
const update = { phoneVerified: true };
const doc = await DeliveryBoy.findOneAndUpdate(filter, update);
updatedDeliveryBoy = await DeliveryBoy.findOne({ phone: phone });
if (updatedDeliveryBoy.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);
}
};
//delete selected deliveryboy
exports.deleteDeliveryBoy = async (req, reply) => {
try {
var supplierId = req.params.supplierId;
var phone = req.query.phone;
const delivery = await DeliveryBoy.findOneAndDelete({ phone: phone,supplierId:supplierId });
reply.send({ status_code: 200, data: delivery});
// return tank;
} catch (err) {
throw boom.boomify(err);
}
};
//update selected Delivery Boy Details
exports.updateDeliveryBoy = async (req, reply) => {
try {
var supplierId = req.params.supplierId;
var phone = req.query.phone;
const delivery = req.body;
const { ...updateData } = delivery;
const update = await DeliveryBoy.findOneAndUpdate({ phone: phone,supplierId:supplierId, }, updateData, { new: true });
console.log(update)
//return update;
reply.send({ status_code: 200, data: update });
}
catch (err) {
throw boom.boomify(err);
}
};
// Get current supplier
exports.getCurrentSupplier = async (req, reply) => {
try {
@ -650,3 +854,59 @@ exports.getPendingSuppliers = async (req, reply) => {
};
exports.getPendingCustomers = async (req, reply) => {
const limit = parseInt(req.query.limit) || 100;
const page = parseInt(req.query.page) || 1;
const startindex = (page - 1) * limit;
const supplierId = req.params.supplierId; // Assuming you have already authenticated the user and stored their ID in the request object
try {
const friendRequests = await FriendRequest.find({ supplierId, status: ["pending","rejected"] });
console.log(friendRequests,supplierId, "su....")
const supplierIdsToInclude = friendRequests.map((request) => request.customerId);
console.log(supplierIdsToInclude, "supplierIdsToInclude..")
await User.find({ customerId: { $in: supplierIdsToInclude } })
.limit(limit)
.skip(startindex)
.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.getconnectedCustomers = async (req, reply) => {
const limit = parseInt(req.query.limit) || 100;
const page = parseInt(req.query.page) || 1;
const startindex = (page - 1) * limit;
const supplierId = req.params.supplierId; // Assuming you have already authenticated the user and stored their ID in the request object
try {
const friendRequests = await FriendRequest.find({ supplierId, status: ["accepted"] });
console.log(friendRequests,supplierId, "su....")
const supplierIdsToInclude = friendRequests.map((request) => request.customerId);
console.log(supplierIdsToInclude, "supplierIdsToInclude..")
await User.find({ customerId: { $in: supplierIdsToInclude } })
.limit(limit)
.skip(startindex)
.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);
}
};

@ -111,6 +111,10 @@ const supplierSchema = new mongoose.Schema(
name: { type: String, default: null },
phone: { type: String, default: null,unique:true },
alternativeContactNumber : { type : String,default: null },
phoneVerified: { type: Boolean, default: false },
phoneVerificationCode: { type: Number, default: 11111 },
passwordResetCode: { type: Number, default: code },
oneTimePasswordSetFlag: { type: Boolean, default: false },
address: { type: String, default: null },
city: { type: String, default: null },
state: { type: String, default: null },

@ -83,6 +83,57 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/pendingCustomers/:supplierId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All pending/rejected Customers",
summary: "This is for to Get All pending/rejected Customers",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getPendingCustomers,
});
fastify.get("/api/connectedCustomers/:supplierId", {
schema: {
tags: ["Supplier-Data"],
description: "This is for Get All connected Customers for Suppliers",
summary: "This is for to Get All connected Customers for suppliers",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: validationHandler.getconnectedCustomers,
});
fastify.post("/api/supplierlogin", {
schema: {
description: "This is for Login Supplier",
@ -101,6 +152,22 @@ module.exports = function (fastify, opts, next) {
});
fastify.post("/api/deliveryboylogin", {
schema: {
description: "This is for Login Delivery Boy",
tags: ["Supplier-Data"],
summary: "This is for Login Delivery Boy",
body: {
type: "object",
required: ["phone"],
properties: {
phone: { type: "string" },
},
},
},
handler: validationHandler.loginDeliveryBoy,
});
fastify.route({
method: "POST",
url: "/api/supplierlogout",
@ -201,6 +268,112 @@ module.exports = function (fastify, opts, next) {
});
fastify.route({
method: "POST",
url: "/api/deliveryboyphone",
schema: {
tags: ["Supplier-Data"],
description: "This is for verify Delivery Boy Phone",
summary: "This is to Verify Delivery Boy Phone.",
body: {
type: "object",
required: ["phone"],
properties: {
phoneVerificationCode: { type: "string" },
phone: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler: validationHandler.deliveryBoyVerifyPhone,
});
fastify.route({
method: "PUT",
url: "/api/deletedeliveryboy/:supplierId",
schema: {
tags: ["Supplier-Data"],
summary: "This is for delete delivery boy",
description: "This is for delete delivery boy",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
querystring: {
phone: {type: 'string'}
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: validationHandler.deleteDeliveryBoy,
});
fastify.route({
method: "PUT",
url: "/api/updatedeliveryboy/:supplierId",
schema: {
tags: ["Supplier-Data"],
summary: "This is for update deliveryboy details",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
querystring: {
phone: {type: 'string'}
},
body: {
type: "object",
// required: ['phone'],
properties: {
name: { type: "string", default: null },
phone: { type: "string", default: null },
alternativeContactNumber: { type: "string" },
address: { type: "string", default: null },
city: { type: "string" , default: null},
state: { type: "string", default: null },
zip: { type: "string", default: null },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
preHandler: fastify.auth([fastify.authenticate]),
handler: validationHandler.updateDeliveryBoy,
});
fastify.route({
method: "POST",
url: "/api/suppliers/:supplierId",

@ -204,9 +204,8 @@ module.exports = function (fastify, opts, next) {
capacity: { type: "string" },
address: { type: "string" },
dateOfOrder: { type: "string"},
tankname:{type: "string"},
tankLocation:{type:"string"}
price: { type: "string"},
supplierId: { type: "string"},
@ -330,6 +329,35 @@ module.exports = function (fastify, opts, next) {
handler: tankersController.getTankersBookingdetails,
});
fastify.get("/api/getAllTankersBookingdetails/:supplierId", {
schema: {
tags: ["Supplier"],
description: "This is for Get All Tanker Booking Data",
summary: "This is for to Get All Tanker Booking Data",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
// querystring: {
// tankerName: {type: 'string'}
// },
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.getAllTankersBookingdetails,
});
fastify.get("/api/getBores", {
schema: {
tags: ["Supplier"],
@ -648,6 +676,30 @@ module.exports = function (fastify, opts, next) {
});
fastify.get("/api/alltankersaccepted/:supplierId", {
schema: {
tags: ["Supplier-Order"],
description: "This is for Get All connected and rejected for Suppliers",
summary: "This is for to Get All connected and rejected for suppliers",
params: {
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
handler: tankersController.getAllTankersaccepted,
});
next();
}

Loading…
Cancel
Save