|
|
|
@ -21,64 +21,104 @@ async function deleteOldRecords() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addTanks = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
// exports.addTanks = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
|
|
// var customerId = req.params.customerId
|
|
|
|
|
// //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;
|
|
|
|
|
|
|
|
|
|
var customerId = req.params.customerId
|
|
|
|
|
//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);
|
|
|
|
|
// tankData = {
|
|
|
|
|
// customerId: customerId,
|
|
|
|
|
// hardwareId: req.body.hardwareId,
|
|
|
|
|
// tankName: req.body.tankName,
|
|
|
|
|
// blockName: req.body.blockName,
|
|
|
|
|
// capacity: req.body.capacity,
|
|
|
|
|
// typeOfWater: req.body.typeOfWater,
|
|
|
|
|
|
|
|
|
|
// tankLocation:req.body.tankLocation.toLowerCase(),
|
|
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
// //console.log( req.body.tankLocation.toLowerCase())
|
|
|
|
|
|
|
|
|
|
// var tank_name = req.body.tankName
|
|
|
|
|
// var tankLocation = req.body.tankLocation.toLowerCase()
|
|
|
|
|
// var i_tank = await Tank.findOne({ tankName: tank_name,customerId:customerId,tankLocation:tankLocation})
|
|
|
|
|
// if(i_tank){
|
|
|
|
|
// throw new Error('tankname already exists');
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
|
|
|
|
|
// var tank = new Tank(tankData);
|
|
|
|
|
|
|
|
|
|
// checkFormEncoding = isUserFormUrlEncoded(req);
|
|
|
|
|
// if (checkFormEncoding.isUserFormUrlEncoded) {
|
|
|
|
|
// usertobeInserted = checkFormEncoding.tank;
|
|
|
|
|
// console.log("thsi true url string");
|
|
|
|
|
// tank.customerId = usertobeInserted.customerId
|
|
|
|
|
// tank.hardwareId = usertobeInserted.hardwareId;
|
|
|
|
|
// tank.tankName = usertobeInserted.tankName;
|
|
|
|
|
// tank.blockName = usertobeInserted.blockName;
|
|
|
|
|
// tank.capacity = usertobeInserted.capacity;
|
|
|
|
|
// tank.typeOfWater = usertobeInserted.typeOfWater;
|
|
|
|
|
|
|
|
|
|
// tank.tankLocation = (usertobeInserted.tankLocation).toLowerCase();
|
|
|
|
|
// console.log((usertobeInserted.tankLocation).toLowerCase())
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// const insertedTank = await tank.save();
|
|
|
|
|
|
|
|
|
|
// console.log("This is the reply in the handler after the validations", reply);
|
|
|
|
|
tankData = {
|
|
|
|
|
// return insertedTank;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } catch (err) {
|
|
|
|
|
// throw boom.boomify(err);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.addTanks = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const { hardwareId, tankhardwareId } = req.body;
|
|
|
|
|
|
|
|
|
|
// Check if the combination of hardwareId and tankhardwareId already exists
|
|
|
|
|
const existingTank = await Tank.findOne({
|
|
|
|
|
customerId: customerId,
|
|
|
|
|
hardwareId: req.body.hardwareId,
|
|
|
|
|
hardwareId: hardwareId,
|
|
|
|
|
tankhardwareId: tankhardwareId,
|
|
|
|
|
tankName:tankName,
|
|
|
|
|
tankLocation:tankLocation.toLowerCase()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (existingTank) {
|
|
|
|
|
throw new Error('The combination of hardwareId and tankhardwareId already exists.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tankData = {
|
|
|
|
|
customerId: customerId,
|
|
|
|
|
hardwareId: hardwareId,
|
|
|
|
|
tankhardwareId: tankhardwareId,
|
|
|
|
|
tankName: req.body.tankName,
|
|
|
|
|
blockName: req.body.blockName,
|
|
|
|
|
capacity: req.body.capacity,
|
|
|
|
|
typeOfWater: req.body.typeOfWater,
|
|
|
|
|
|
|
|
|
|
tankLocation:req.body.tankLocation.toLowerCase(),
|
|
|
|
|
|
|
|
|
|
tankLocation: req.body.tankLocation.toLowerCase(),
|
|
|
|
|
// ... other fields
|
|
|
|
|
};
|
|
|
|
|
//console.log( req.body.tankLocation.toLowerCase())
|
|
|
|
|
|
|
|
|
|
var tank_name = req.body.tankName
|
|
|
|
|
var tankLocation = req.body.tankLocation.toLowerCase()
|
|
|
|
|
var i_tank = await Tank.findOne({ tankName: tank_name,customerId:customerId,tankLocation:tankLocation})
|
|
|
|
|
if(i_tank){
|
|
|
|
|
throw new Error('tankname already exists');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
var tank = new Tank(tankData);
|
|
|
|
|
|
|
|
|
|
checkFormEncoding = isUserFormUrlEncoded(req);
|
|
|
|
|
if (checkFormEncoding.isUserFormUrlEncoded) {
|
|
|
|
|
usertobeInserted = checkFormEncoding.tank;
|
|
|
|
|
console.log("thsi true url string");
|
|
|
|
|
tank.customerId = usertobeInserted.customerId
|
|
|
|
|
tank.hardwareId = usertobeInserted.hardwareId;
|
|
|
|
|
tank.tankName = usertobeInserted.tankName;
|
|
|
|
|
tank.blockName = usertobeInserted.blockName;
|
|
|
|
|
tank.capacity = usertobeInserted.capacity;
|
|
|
|
|
tank.typeOfWater = usertobeInserted.typeOfWater;
|
|
|
|
|
|
|
|
|
|
tank.tankLocation = (usertobeInserted.tankLocation).toLowerCase();
|
|
|
|
|
console.log((usertobeInserted.tankLocation).toLowerCase())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tank = new Tank(tankData);
|
|
|
|
|
const insertedTank = await tank.save();
|
|
|
|
|
|
|
|
|
|
return insertedTank;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|