Bhaskar 6 months ago
commit 26b073a23e

@ -2800,6 +2800,7 @@ exports.motorAction = async (req, reply) => {
{ role: "Staff", name: users.staff.staff.find(staff => staff.phone === phone).name, phone } : null;
if (!loggedInUser) return reply.status(404).send({ error: "User not found" });
console.log(loggedInUser)
const fcmToken = users.fcmIds ? users.fcmIds.filter(id => id) : [];
const receiverTank = await Tank.findOne({ customerId, tankName: req.body.to, tankLocation: req.body.to_type.toLowerCase() });
@ -2854,7 +2855,8 @@ exports.motorAction = async (req, reply) => {
supplier_type: req.body.from_type,
receiver_type: req.body.to_type,
startTime: req.body.startTime,
receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10)
receiverInitialwaterlevel: parseInt(receiverTank.waterlevel, 10),
started_by:loggedInUser.name
});
await newMotorData.save();
console.log("entered time",motorId,motorStopStatus)
@ -2989,7 +2991,8 @@ exports.motorAction = async (req, reply) => {
stopTime: currentTime,
receiverfinalwaterlevel: receiverFinalWaterLevel.toString(),
quantity_delivered: quantityDelivered.toString(),
runtime: runtime.toString()
runtime: runtime.toString(),
stopped_by:loggedInUser.name
}
}
);
@ -3021,7 +3024,8 @@ exports.motorAction = async (req, reply) => {
receiver_type: req.body.to_type,
startTime: req.body.startTime,
receiverInitialwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10),
supplierInitialwaterlevel:parseInt(supplier_tank_info7.waterlevel, 10)
supplierInitialwaterlevel:parseInt(supplier_tank_info7.waterlevel, 10),
started_by:loggedInUser.name
});
await newMotorData.save();
// If threshold type is percentage, calculate percentage threshold
@ -3102,7 +3106,8 @@ exports.motorAction = async (req, reply) => {
$set: {
stopTime:stopTime,
receiverfinalwaterlevel: receiverFinalWaterLevel.toString(),
quantity_delivered: quantityDelivered.toString()
quantity_delivered: quantityDelivered.toString(),
stopped_by:loggedInUser.name
}
}
);
@ -3121,7 +3126,8 @@ exports.motorAction = async (req, reply) => {
});
let dynamicInstanceId = null;
let user_name = loggedInUser.name
console.log(user_name,"user_name in stop1")
if (tankWithMotor) {
const connection = tankWithMotor.connections.inputConnections.find(conn => conn.motor_id === motorId);
if (connection && connection.start_instance_id) {
@ -3129,7 +3135,7 @@ exports.motorAction = async (req, reply) => {
}
}
await stopMotor(motorId, customerId, dynamicInstanceId);
await stopMotor(motorId, customerId, dynamicInstanceId,user_name);
try {
@ -3166,7 +3172,8 @@ exports.motorAction = async (req, reply) => {
};
async function stopMotor(motorId, customerId, start_instance_id) {
async function stopMotor(motorId, customerId, start_instance_id,user_name) {
console.log(user_name,"user_name in stop2")
const currentTime = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm');
await Tank.updateOne(
{ customerId, "connections.inputConnections.motor_id": motorId },
@ -3200,7 +3207,7 @@ async function stopMotor(motorId, customerId, start_instance_id) {
await MotorData.updateOne(
{ customerId, motor_id: motorId, start_instance_id },
{ $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime } }
{ $set: { stopTime: currentTime, receiverfinalwaterlevel: receiverFinalWaterLevel.toString(), quantity_delivered: quantityDelivered.toString(), runtime: runtime,stopped_by:user_name } }
);
}
}
@ -6094,7 +6101,8 @@ async function processIotData(hw_Id, data) {
supplier_type: inputConnection.input_type,
receiver_type: motorTank.tankLocation,
startTime: formattedTime,
receiverInitialwaterlevel: parseInt(inputConnection.water_level, 10)
receiverInitialwaterlevel: parseInt(inputConnection.water_level, 10),
started_by:"manual"
});
await newMotorData.save();
@ -6143,7 +6151,8 @@ async function processIotData(hw_Id, data) {
stopTime: currentTime,
receiverfinalwaterlevel: receiverFinalWaterLevel.toString(),
quantity_delivered: quantityDelivered.toString(),
runtime: runtime.toString()
runtime: runtime.toString(),
stopped_by:"manual"
}
}
);

@ -142,7 +142,8 @@ const motordataSchema = new mongoose.Schema({
quantity_delivered:{ type: String, default: null },
receiverInitialwaterlevel: { type: String, default: "0" },
receiverfinalwaterlevel: { type: String, default: "0" },
started_by: { type: String, default: "user" },
stopped_by: { type: String, default: "user" }
});

Loading…
Cancel
Save