You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
3.7 KiB
129 lines
3.7 KiB
|
|
//const Supplier = require("../models/supplier");
|
|
const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
|
|
|
|
const boom = require("boom");
|
|
const fastify = require("fastify")({
|
|
logger: true,
|
|
});
|
|
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
|
|
|
|
|
|
|
|
|
|
exports.orderNow = async (req, reply) => {
|
|
|
|
try {
|
|
const customerId = req.body.customerId;
|
|
const bookingId = req.params.bookingId;
|
|
const tankerName = req.body.tankerName;
|
|
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.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 {
|
|
booking_info.orderStatus = "rejected"
|
|
|
|
}
|
|
|
|
const booking = await booking_info.save();
|
|
return booking;
|
|
|
|
} catch (err) {
|
|
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);
|
|
}
|
|
};
|
|
|
|
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);
|
|
}
|
|
};
|
|
|