made changes in tanker.js,tankercontrollers,tanker routes

master
varun 3 years ago
parent 19f847be0c
commit a12804ef33

@ -75,6 +75,71 @@ console.log(req.params);
}
};
exports.addTankers1 = async (req, reply) => {
try {
//const username = req.params.username;
console.log(req.params);
const supplierId = req.params.supplierId;
//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);
tankersData = {
supplierId:supplierId,
supplier_name:req.body.supplier_name,
supplier_address : req.body.supplier_address,
tankerName: req.body.tankerName,
phoneNumber: req.body.phoneNumber,
alternative_phoneNumber: req.body.alternative_phoneNumber,
typeofwater: req.body.typeofwater,
capacity: req.body.capacity,
price: req.body.price,
status: req.body.status
};
console.log(req.body.typeofwater,req.body.capacity)
var tanker_Name = req.body.tankerName
var i_tank = await Tanker.findOne({ tankerName: tanker_Name,supplierId:supplierId})
if(i_tank){
throw new Error('tankername already exists');
}
else {
var tankers = new Tanker(tankersData);
checkFormEncoding = isUserFormUrlEncoded(req);
if (checkFormEncoding.isUserFormUrlEncoded) {
usertobeInserted = checkFormEncoding.tankers;
console.log("thsi true url string");
tankers.supplier_name = usertobeInserted.supplier_name;
tankers.supplier_address = usertobeInserted.supplier_address;
tankers.tankerName = usertobeInserted.tankerName;
tankers.phoneNumber = usertobeInserted.phoneNumber;
tankers.alternative_phoneNumber = usertobeInserted.alternative_phoneNumber;
tankers.capacity = usertobeInserted.capacity;
tankers.typeofwater = usertobeInserted.typeofwater;
tankers.price = usertobeInserted.price;
tankers.status = usertobeInserted.status;
}
}
const insertedTanker = await tankers.save();
return insertedTanker;
} catch (err) {
throw boom.boomify(err);
}
};
//update selected tanker
exports.updateTankersInfo = async (req, reply) => {

@ -570,6 +570,80 @@ module.exports = function (fastify, opts, next) {
handler: tankersController.status,
});
module.exports = function (fastify, opts, next) {
fastify.route({
method: "POST",
url: "/api/addTankers5/:supplierId",
schema: {
tags: ["Supplier"],
description: "This is to cretae New Tanker",
summary: "This is to Create New Tanker.",
params: {
required: ["supplierId"],
type: "object",
properties: {
supplierId: {
type: "string",
description: "supplierId",
},
},
},
body: {
type: "object",
properties: {
supplier_name: { type: "string" },
supplier_address:{ type: "string" },
tankerName: { type: "string" },
phoneNumber: { type: "string"},
alternative_phoneNumber: { type: "string"},
typeofwater: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
typeofwater: { type: "string", default: null },
},
},
},
price: {
type: "array",
maxItems: 2500,
items: {
type: "object",
properties: {
price: { type: "string", default: null },
},
},
},
capacity: { type: "string"},
status: {type: "string"}
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: tankersController.addTankers1,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
});
next();
}

Loading…
Cancel
Save