|
|
@ -3264,14 +3264,31 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if (!height || !width || !length) {
|
|
|
|
// if (height === undefined || width === undefined || length === undefined) {
|
|
|
|
// return reply.code(400).send({
|
|
|
|
// return reply.code(400).send({
|
|
|
|
// success: false,
|
|
|
|
// success: false,
|
|
|
|
// message: 'height, width and length are required in body'
|
|
|
|
// message: 'height, width and length are required in body (in cm)'
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Step 1: Find install record with teamMemberId (must be assigned)
|
|
|
|
if (
|
|
|
|
|
|
|
|
isNaN(parseFloat(height)) ||
|
|
|
|
|
|
|
|
isNaN(parseFloat(width)) ||
|
|
|
|
|
|
|
|
isNaN(parseFloat(length))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
message: 'height, width and length must be numeric values (in cm)'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Helper: cm to feet
|
|
|
|
|
|
|
|
const cmToFeet = (cm) => {
|
|
|
|
|
|
|
|
const v = parseFloat(cm);
|
|
|
|
|
|
|
|
return !isNaN(v) ? parseFloat((v / 30.48).toFixed(2)) : null;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 1: Find install record with teamMemberId
|
|
|
|
const installRecord = await Install.findOne({
|
|
|
|
const installRecord = await Install.findOne({
|
|
|
|
'team_member.team_member.teamMemberId': teamMemberId
|
|
|
|
'team_member.team_member.teamMemberId': teamMemberId
|
|
|
|
}).lean();
|
|
|
|
}).lean();
|
|
|
@ -3293,7 +3310,8 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
message: 'Team member details not found under install record'
|
|
|
|
message: 'Team member details not found under install record'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Step 2: Find the matching order using installationId from install and customerId
|
|
|
|
|
|
|
|
|
|
|
|
// Step 2: Find the matching order using installationId and customerId
|
|
|
|
const orderRecord = await Order.findOne({
|
|
|
|
const orderRecord = await Order.findOne({
|
|
|
|
installationId: installRecord.installationId,
|
|
|
|
installationId: installRecord.installationId,
|
|
|
|
customerId
|
|
|
|
customerId
|
|
|
@ -3306,7 +3324,12 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Step 3: Update the tank document in Tanks collection
|
|
|
|
// Step 3: Convert cm to feet before saving
|
|
|
|
|
|
|
|
const heightInFeet = cmToFeet(height);
|
|
|
|
|
|
|
|
const widthInFeet = cmToFeet(width);
|
|
|
|
|
|
|
|
const lengthInFeet = cmToFeet(length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 4: Update the tank
|
|
|
|
const updatedTank = await Tank.findOneAndUpdate(
|
|
|
|
const updatedTank = await Tank.findOneAndUpdate(
|
|
|
|
{
|
|
|
|
{
|
|
|
|
customerId,
|
|
|
|
customerId,
|
|
|
@ -3314,7 +3337,11 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
tankhardwareId: tankHardwareId
|
|
|
|
tankhardwareId: tankHardwareId
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$set: { height, width, length }
|
|
|
|
$set: {
|
|
|
|
|
|
|
|
height: heightInFeet,
|
|
|
|
|
|
|
|
width: widthInFeet,
|
|
|
|
|
|
|
|
length: lengthInFeet
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ new: true }
|
|
|
|
{ new: true }
|
|
|
|
).lean();
|
|
|
|
).lean();
|
|
|
@ -3326,10 +3353,16 @@ exports.editTankDimensions = async (req, reply) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 5: Return success response with both feet & original cm
|
|
|
|
return reply.send({
|
|
|
|
return reply.send({
|
|
|
|
success: true,
|
|
|
|
success: true,
|
|
|
|
message: 'Tank dimensions updated successfully',
|
|
|
|
message: 'Tank dimensions updated successfully',
|
|
|
|
updatedTank,
|
|
|
|
updatedTank: {
|
|
|
|
|
|
|
|
...updatedTank,
|
|
|
|
|
|
|
|
heightIncm: parseFloat(height),
|
|
|
|
|
|
|
|
widthIncm: parseFloat(width),
|
|
|
|
|
|
|
|
lengthIncm: parseFloat(length)
|
|
|
|
|
|
|
|
},
|
|
|
|
teamMember: {
|
|
|
|
teamMember: {
|
|
|
|
teamMemberId: teamMemberDetails.teamMemberId,
|
|
|
|
teamMemberId: teamMemberDetails.teamMemberId,
|
|
|
|
firstName: teamMemberDetails.firstName,
|
|
|
|
firstName: teamMemberDetails.firstName,
|
|
|
|