ashok 3 months ago
commit 2573185fca

@ -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({
// 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({
'team_member.team_member.teamMemberId': teamMemberId
}).lean();
@ -3293,7 +3310,8 @@ exports.editTankDimensions = async (req, reply) => {
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({
installationId: installRecord.installationId,
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(
{
customerId,
@ -3314,7 +3337,11 @@ exports.editTankDimensions = async (req, reply) => {
tankhardwareId: tankHardwareId
},
{
$set: { height, width, length }
$set: {
height: heightInFeet,
width: widthInFeet,
length: lengthInFeet
}
},
{ new: true }
).lean();
@ -3326,11 +3353,17 @@ exports.editTankDimensions = async (req, reply) => {
});
}
// Step 5: Return success response with both feet & original cm
return reply.send({
success: true,
message: 'Tank dimensions updated successfully',
updatedTank,
teamMember: {
updatedTank: {
...updatedTank,
heightIncm: parseFloat(height),
widthIncm: parseFloat(width),
lengthIncm: parseFloat(length)
},
teamMember: {
teamMemberId: teamMemberDetails.teamMemberId,
firstName: teamMemberDetails.firstName,
phone: teamMemberDetails.phone,

@ -501,9 +501,9 @@ fastify.put('/api/tanks/:customerId/:teamMemberId/:hardwareId/:tankHardwareId',
type: 'object',
//required: ['height', 'width', 'length'],
properties: {
height: { type: 'string', description: 'New tank height' },
width: { type: 'string', description: 'New tank width' },
length: { type: 'string', description: 'New tank length' }
height: { type: 'number', description: 'New tank height (in cm)' },
width: { type: 'number', description: 'New tank width (in cm)' },
length: { type: 'number', description: 'New tank length (in cm)' }
}
},

Loading…
Cancel
Save