|
|
@ -160,23 +160,53 @@ exports.updateTanksInfo = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//delete selected tank
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.deleteTanksInfo = async (req, reply) => {
|
|
|
|
exports.deleteTanksInfo = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
const { tankName } = req.query;
|
|
|
|
const tankName = req.query.tankName;
|
|
|
|
|
|
|
|
const tankLocation = req.body.tankLocation.toLowerCase();
|
|
|
|
const tankLocation = req.body.tankLocation.toLowerCase();
|
|
|
|
const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId,tankLocation:tankLocation });
|
|
|
|
if (!tankName || !tankLocation) {
|
|
|
|
|
|
|
|
return reply.code(400).send({ message: "Tank name and location are required" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: tank});
|
|
|
|
// Convert tankLocation to lowercase (for case-insensitive match)
|
|
|
|
// return tank;
|
|
|
|
const normalizedTankLocation = tankLocation.toLowerCase();
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
// Find and delete the main tank
|
|
|
|
|
|
|
|
const deletedTank = await Tank.findOneAndDelete({
|
|
|
|
|
|
|
|
customerId,
|
|
|
|
|
|
|
|
tankName,
|
|
|
|
|
|
|
|
tankLocation: normalizedTankLocation
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!deletedTank) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: "Tank not found" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the deleted tank from inputConnections and outputConnections in all other tanks
|
|
|
|
|
|
|
|
await Tank.updateMany(
|
|
|
|
|
|
|
|
{ customerId },
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$pull: {
|
|
|
|
|
|
|
|
"connections.inputConnections": { inputConnections: tankName },
|
|
|
|
|
|
|
|
"connections.outputConnections": { outputConnections: tankName }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({ message: "Tank deleted successfully" });
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error("Error deleting tank:", error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ message: "Internal Server Error" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getConnectionsInfoOfParticularTank = async (req, reply) => {
|
|
|
|
exports.getConnectionsInfoOfParticularTank = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const customerId = req.params.customerId;
|
|
|
@ -6315,3 +6345,72 @@ cron.schedule(
|
|
|
|
|
|
|
|
|
|
|
|
// // Call the function to update stopTime
|
|
|
|
// // Call the function to update stopTime
|
|
|
|
// updateStopTimeFormat();
|
|
|
|
// updateStopTimeFormat();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updatetankstatus = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
const { tankName, tankLocation, status } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!["active", "inactive"].includes(status)) {
|
|
|
|
|
|
|
|
return reply.code(400).send({ message: "Invalid status value" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the main tank
|
|
|
|
|
|
|
|
const mainTank = await Tank.findOneAndUpdate(
|
|
|
|
|
|
|
|
{ customerId, tankName, tankLocation },
|
|
|
|
|
|
|
|
{ $set: { status } },
|
|
|
|
|
|
|
|
{ new: true }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mainTank) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: "Tank not found" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update status in related outputConnections tanks
|
|
|
|
|
|
|
|
await Tank.updateMany(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
customerId,
|
|
|
|
|
|
|
|
"connections.outputConnections.outputConnections": tankName,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ $set: { "connections.outputConnections.$.status": status } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update status in related inputConnections tanks
|
|
|
|
|
|
|
|
await Tank.updateMany(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
customerId,
|
|
|
|
|
|
|
|
"connections.inputConnections.inputConnections": tankName,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ $set: { "connections.inputConnections.$.status": status } }
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({ message: "Tank status updated successfully" });
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error("Error updating tank status:", error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ message: "Internal Server Error" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.listofactiveandinactivetankstatus = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
const { status } = req.query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!["active", "inactive"].includes(status)) {
|
|
|
|
|
|
|
|
return reply.code(400).send({ message: "Invalid status value" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find tanks based on customerId and status
|
|
|
|
|
|
|
|
const tanks = await Tank.find({ customerId, status });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.send({ tanks });
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error("Error fetching tank list:", error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ message: "Internal Server Error" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|