|
|
|
@ -3137,6 +3137,85 @@ exports.getMasterWithSlaves = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.editTankDimensions = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId, teamMemberId, hardwareId, tankHardwareId } = req.params;
|
|
|
|
|
const { height, width, length } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!customerId || !teamMemberId || !hardwareId || !tankHardwareId) {
|
|
|
|
|
return reply.code(400).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'customerId, teamMemberId, hardwareId and tankHardwareId are required'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (!height || !width || !length) {
|
|
|
|
|
// return reply.code(400).send({
|
|
|
|
|
// success: false,
|
|
|
|
|
// message: 'height, width and length are required in body'
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// Step 1: Find install record with teamMemberId (must be assigned)
|
|
|
|
|
const installRecord = await Install.findOne({
|
|
|
|
|
'team_member.team_member.teamMemberId': teamMemberId
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
if (!installRecord) {
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Team member not found or not assigned'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 2: Find the matching order using installationId from install and customerId
|
|
|
|
|
const orderRecord = await Order.findOne({
|
|
|
|
|
installationId: installRecord.installationId,
|
|
|
|
|
customerId
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
if (!orderRecord) {
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Order not found for this installation and customer'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3: Update the tank document in Tanks collection
|
|
|
|
|
const updatedTank = await Tank.findOneAndUpdate(
|
|
|
|
|
{
|
|
|
|
|
customerId,
|
|
|
|
|
hardwareId,
|
|
|
|
|
tankhardwareId: tankHardwareId
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
$set: { height, width, length }
|
|
|
|
|
},
|
|
|
|
|
{ new: true }
|
|
|
|
|
).lean();
|
|
|
|
|
|
|
|
|
|
if (!updatedTank) {
|
|
|
|
|
return reply.code(404).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Tank not found with given customerId, hardwareId and tankHardwareId'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
success: true,
|
|
|
|
|
message: 'Tank dimensions updated successfully',
|
|
|
|
|
updatedTank
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error updating tank dimensions:', error);
|
|
|
|
|
return reply.code(500).send({
|
|
|
|
|
success: false,
|
|
|
|
|
message: 'Internal server error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getPendingMasterSlaveSummary = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|