|
|
|
@ -2035,7 +2035,7 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!height || !width || !length || !unit) {
|
|
|
|
|
if (height === undefined || width === undefined || length === undefined || !unit) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'height, width, length and unit are required in body'
|
|
|
|
@ -2061,31 +2061,30 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 1: Convert to feet if input is cm
|
|
|
|
|
// Step 1: Convert to feet if input is in cm (keep floats)
|
|
|
|
|
let heightInFeet, widthInFeet, lengthInFeet;
|
|
|
|
|
|
|
|
|
|
if (unit === 'cm') {
|
|
|
|
|
heightInFeet = heightNum / 30.48;
|
|
|
|
|
widthInFeet = widthNum / 30.48;
|
|
|
|
|
lengthInFeet = lengthNum / 30.48;
|
|
|
|
|
} else {
|
|
|
|
|
heightInFeet = heightNum;
|
|
|
|
|
widthInFeet = widthNum;
|
|
|
|
|
lengthInFeet = lengthNum;
|
|
|
|
|
}
|
|
|
|
|
heightInFeet = Number((heightNum / 30.48).toFixed(2));
|
|
|
|
|
widthInFeet = Number((widthNum / 30.48).toFixed(2));
|
|
|
|
|
lengthInFeet = Number((lengthNum / 30.48).toFixed(2));
|
|
|
|
|
} else {
|
|
|
|
|
heightInFeet = Number(heightNum.toFixed(2));
|
|
|
|
|
widthInFeet = Number(widthNum.toFixed(2));
|
|
|
|
|
lengthInFeet = Number(lengthNum.toFixed(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Round to nearest integer
|
|
|
|
|
const heightFeetInt = Math.round(heightInFeet);
|
|
|
|
|
const widthFeetInt = Math.round(widthInFeet);
|
|
|
|
|
const lengthFeetInt = Math.round(lengthInFeet);
|
|
|
|
|
|
|
|
|
|
// Step 2: Calculate capacity & waterCapacityPerCm (still use float here for precision)
|
|
|
|
|
const height_m = heightFeetInt * 0.3048;
|
|
|
|
|
const width_m = widthFeetInt * 0.3048;
|
|
|
|
|
const length_m = lengthFeetInt * 0.3048;
|
|
|
|
|
// Step 2: Calculate capacity & waterCapacityPerCm (use floats for precision)
|
|
|
|
|
const height_m = heightInFeet * 0.3048;
|
|
|
|
|
const width_m = widthInFeet * 0.3048;
|
|
|
|
|
const length_m = lengthInFeet * 0.3048;
|
|
|
|
|
|
|
|
|
|
const capacity = Math.round(length_m * width_m * height_m * 1000); // liters, integer
|
|
|
|
|
const waterCapacityPerCm = Math.round(length_m * width_m * 0.01 * 1000); // liters per cm, integer
|
|
|
|
|
// const capacity = length_m * width_m * height_m * 1000; // in liters
|
|
|
|
|
// const waterCapacityPerCm = length_m * width_m * 0.01 * 1000; // liters per cm
|
|
|
|
|
|
|
|
|
|
const capacity = Number((length_m * width_m * height_m * 1000).toFixed(2));
|
|
|
|
|
const waterCapacityPerCm = Number((length_m * width_m * 0.01 * 1000).toFixed(2));
|
|
|
|
|
|
|
|
|
|
// Step 3: Find install record
|
|
|
|
|
const installRecord = await Install.findOne({
|
|
|
|
@ -2123,7 +2122,7 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 5: Update tank dimensions in feet & calculated fields
|
|
|
|
|
// Step 5: Update tank dimensions (use floats, convert to string to store)
|
|
|
|
|
const updatedTank = await Tank.findOneAndUpdate(
|
|
|
|
|
{
|
|
|
|
|
customerId,
|
|
|
|
@ -2132,12 +2131,13 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
$set: {
|
|
|
|
|
height: heightFeetInt, // save as integer in feet
|
|
|
|
|
width: widthFeetInt,
|
|
|
|
|
length: lengthFeetInt,
|
|
|
|
|
capacity: capacity.toString(), // save as string
|
|
|
|
|
height: heightInFeet,
|
|
|
|
|
width: widthInFeet,
|
|
|
|
|
length: lengthInFeet,
|
|
|
|
|
capacity: capacity.toString(),
|
|
|
|
|
waterCapacityPerCm: waterCapacityPerCm.toString()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
).lean();
|
|
|
|
@ -2175,6 +2175,7 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateWorkStatusAndProductStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { connectedTo, teamMemberId, customerId } = req.params;
|
|
|
|
|