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.
78 lines
2.1 KiB
78 lines
2.1 KiB
3 years ago
|
const Tank = require("../models/tanks");
|
||
|
const User = require("../models/User");
|
||
|
const boom = require("boom");
|
||
|
const fastify = require("fastify")({
|
||
|
logger: true,
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
exports.addTanks = async (req, reply) => {
|
||
|
try {
|
||
|
|
||
|
//const username = req.params.username;
|
||
|
|
||
|
console.log(req.params);
|
||
|
// const { username } = req.params;
|
||
|
// 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 = {
|
||
|
//userName: username,
|
||
|
tankName: req.body.tankName,
|
||
|
blockName: req.body.blockName,
|
||
|
capacity: req.body.capacity,
|
||
|
typeOfWater: req.body.typeOfWater,
|
||
|
tankLocation:req.body.tankLocation,
|
||
|
};
|
||
|
|
||
|
var tank = new Tank(tankData);
|
||
|
|
||
|
checkFormEncoding = isUserFormUrlEncoded(req);
|
||
|
if (checkFormEncoding.isUserFormUrlEncoded) {
|
||
|
usertobeInserted = checkFormEncoding.tank;
|
||
|
console.log("thsi true url string");
|
||
|
tank.tankName = usertobeInserted.tankName;
|
||
|
tank.blockName = usertobeInserted.blockName;
|
||
|
tank.capacity = usertobeInserted.capacity;
|
||
|
tank.typeOfWater = usertobeInserted.typeOfWater;
|
||
|
tank.tankLocation = usertobeInserted.tankLocation;
|
||
|
}
|
||
|
|
||
|
const insertedTank = await tank.save();
|
||
|
|
||
|
return insertedTank;
|
||
|
|
||
|
|
||
|
} catch (err) {
|
||
|
throw boom.boomify(err);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
exports.editTanksInfo = async (req, body) => {
|
||
|
|
||
|
try {
|
||
|
const { tankId } = req.params;
|
||
|
const tankInfo = await Tank.findById(tankId);
|
||
|
const updateData = req.body;
|
||
|
console.log(updateData.tankName);
|
||
|
|
||
|
if (updateData.tankName) tankInfo.tankName = updateData.tankName;
|
||
|
if (updateData.blockName) tankInfo.blockName = updateData.blockName;
|
||
|
if (updateData.capacity) tankInfo.capacity = updateData.capacity;
|
||
|
if (updateData.typeOfWater) tankInfo.typeOfWater = updateData.typeOfWater;
|
||
|
if (updateData.tankLocation) tankInfo.tankLocation = updateData.tankLocation;
|
||
|
|
||
|
const tanks = await tankInfo.save();
|
||
|
return tanks;
|
||
|
}
|
||
|
catch (err) {
|
||
|
throw boom.boomify(err);
|
||
|
}
|
||
|
|
||
|
};
|