|
|
|
@ -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,
|
|
|
|
@ -19,9 +21,18 @@ exports.orderNow = async (req, reply) => {
|
|
|
|
|
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 {
|
|
|
|
@ -37,3 +48,65 @@ exports.orderNow = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|