Bhaskara Kishore 3 years ago
commit 8d57fc40ef

@ -1,5 +1,7 @@
const Supplier = require("../models/supplier");
//const Supplier = require("../models/supplier");
const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
const boom = require("boom");
const fastify = require("fastify")({
logger: true,
@ -18,10 +20,19 @@ exports.orderNow = async (req, reply) => {
const booking_info = await Tankerbooking.findOne({ bookingid: bookingId})
const action = req.body.action
const typeofwater = req.body.typeofwater
if(action === "accept"){
const price = req.body.price
const delivery_agent = req.body.delivery_agent
const agent_mobile = req.body.agent_mobile
const agent_alternative_mobile = req.body.agent_alternative_mobile
booking_info.orderStatus = "accepted"
booking_info.price = "500"
booking_info.delivery_agent = delivery_agent
booking_info.delivery_agent_mobile = agent_mobile
booking_info.delivery_agent_alternative_mobile = agent_alternative_mobile
booking_info.price = price
}
else {
@ -36,4 +47,66 @@ exports.orderNow = async (req, reply) => {
throw boom.boomify(err);
}
};
exports.addDeliveryboy = async (req, reply) => {
try {
const supplierId = req.params.supplierId
//const username = req.params.username;
console.log(req.params);
//const {username} = loginObject.user.username;
//console.log(loginObject.user.username)
// const userInfo = await User.findOne({ username: username.toString() });
// const updateData = req.body;
// console.log("This is the reply in the handler after the validations", reply);
deliveryData = {
supplierId: supplierId,
name: req.body.Name,
phone: req.body.phone,
alternativeContactNumber: req.body.alternativeContactNumber,
address: req.body.address,
city:req.body.city,
state:req.body.state,
zip:req.body.zip,
};
var agent_mobile = req.body.phone
var i_agent = await DeliveryBoy.findOne({ phone: agent_mobile})
if(i_agent){
throw new Error('phone already exists');
}
else {
var agent = new DeliveryBoy(deliveryData);
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.agent;
console.log("thsi true url string");
agent.supplierId = usertobeInserted.supplierId
agent.name = usertobeInserted.name;
agent.phone = usertobeInserted.phone;
agent.alternativeContactNumber = usertobeInserted.alternativeContactNumber;
agent.address = usertobeInserted.address;
agent.city = usertobeInserted.city
agent.state = usertobeInserted.state
agent.zip = usertobeInserted.zip
}
}
const insertedagent = await agent.save();
return insertedagent;
} catch (err) {
throw boom.boomify(err);
}
};

@ -100,10 +100,24 @@ const supplierSchema = new mongoose.Schema(
timestamp: { type: Date, default: Date.now }
});
const deliveryBoySchema = new mongoose.Schema({
name: { type: String, default: null },
phone: { type: String, default: null,unique:true },
alternativeContactNumber : { type : String,default: null },
address: { type: String, default: null },
city: { type: String, default: null },
state: { type: String, default: null },
zip: { type: String, default: null },
timestamp: { type: Date, default: Date.now },
status: { type: String, default: "active" },
});
const Supplier = mongoose.model("Supplier", supplierSchema);
//const DeliveryAgent = mongoose.model("DeliveryAgent", deliveryAgent);
const FriendRequest = mongoose.model('FriendRequest', friendRequestSchema);
const DeliveryBoy = mongoose.model('DeliveryBoy', deliveryBoySchema);
module.exports = { Supplier, generateSupplierId, FriendRequest}
module.exports = { Supplier, generateSupplierId, FriendRequest,DeliveryBoy}

@ -34,6 +34,12 @@ module.exports = function (fastify, opts, next) {
customer_address: { type: "string" },
dateOfOrder: { type: "string"},
action:{type:"string"},
price :{type:"string"},
delivery_agent :{type:"string"},
agent_mobile :{type:"string"},
agent_alternative_mobile :{type:"string"},
},
},
security: [
@ -51,8 +57,52 @@ module.exports = function (fastify, opts, next) {
//onResponse: validationHandler.sendPhoneVerificationCode,
});
fastify.route({
method: "POST",
url: "/api/addDeliveryboys/:supplierId",
schema: {
tags: ["Supplier-Data"],
description: "This is for adding delivery boys",
summary: "This is for adding delivery boys",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
body: {
type: "object",
properties: {
Name: { type: "string" },
phone: { type: "string" },
alternativeContactNumber : { type : "string" },
address: { type: "string", default: null },
city: { type: "string", default: null },
state: { type: "string", default: null },
zip: { type: "string", default: null },
status: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: [
//validationHandler.fieldCheck,
//validationHandler.verifySupplier,
// validationHandler.validatePhoneFormat,
//validationHandler.validateEmailFormat,
],
handler: supplierOrderController.addDeliveryboy,
});
next();

Loading…
Cancel
Save