@ -12,6 +12,7 @@ const fastify = require("fastify")({
exports . addTankers = async ( req , reply ) => {
exports . addTankers = async ( req , reply ) => {
try {
try {
@ -28,7 +29,72 @@ console.log(req.params);
tankersData = {
tankersData = {
supplierId : supplierId ,
supplierId : supplierId ,
supplier _name : req . body . username ,
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 ) ;
}
} ;
exports . deleteTankerInfo1 = 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 ,
supplier _address : req . body . supplier _address ,
tankerName : req . body . tankerName ,
tankerName : req . body . tankerName ,
phoneNumber : req . body . phoneNumber ,
phoneNumber : req . body . phoneNumber ,
@ -36,6 +102,7 @@ console.log(req.params);
typeofwater : req . body . typeofwater ,
typeofwater : req . body . typeofwater ,
capacity : req . body . capacity ,
capacity : req . body . capacity ,
price : req . body . price ,
price : req . body . price ,
status : req . body . status
} ;
} ;
console . log ( req . body . typeofwater , req . body . capacity )
console . log ( req . body . typeofwater , req . body . capacity )
@ -60,7 +127,7 @@ console.log(req.params);
tankers . capacity = usertobeInserted . capacity ;
tankers . capacity = usertobeInserted . capacity ;
tankers . typeofwater = usertobeInserted . typeofwater ;
tankers . typeofwater = usertobeInserted . typeofwater ;
tankers . price = usertobeInserted . price ;
tankers . price = usertobeInserted . price ;
tankers . s upplierId = usertobeInserted . supplierId ;
tankers . s tatus = usertobeInserted . status ;
}
}
}
}
const insertedTanker = await tankers . save ( ) ;
const insertedTanker = await tankers . save ( ) ;
@ -437,3 +504,26 @@ exports.updatePipelineInfo = async (req, reply) => {
}
}
} ;
} ;
exports . status = async ( req , reply ) => {
try {
var status = req . query . status ;
if ( status === 'connected' ) {
try {
const tankers = await Tanker . find ( { } ) ;
console . log ( "tankers..." , tankers )
reply . send ( tankers ) ;
} catch ( err ) {
reply . send ( { message : err } ) ;
}
} else {
reply . send ( { message : 'Not Connected' } ) ;
}
}
catch ( err ) {
throw boom . boomify ( err ) ;
}
} ;