update the tank dimensions

master^2
Bhaskar 3 months ago
parent aa8bfc04f4
commit 0da6e85ce8

@ -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) => { exports.getPendingMasterSlaveSummary = async (req, reply) => {
try { try {

@ -445,7 +445,7 @@ module.exports = function (fastify, opts, next) {
properties: { properties: {
work_status: { work_status: {
type: 'string', type: 'string',
enum: ['active', 'pending', 'complete','waiting'], // update enum based on what your Orders schema allows enum: ['active', 'pending', 'complete','waiting','reject'], // update enum based on what your Orders schema allows
description: 'New work status to set in master_connections' description: 'New work status to set in master_connections'
} }
} }
@ -482,6 +482,34 @@ module.exports = function (fastify, opts, next) {
} }
); );
fastify.put('/api/tanks/:customerId/:teamMemberId/:hardwareId/:tankHardwareId', {
schema: {
tags: ['Installation'],
summary: 'Update tank dimensions',
description: 'Edit tank details (height, width, length) by customerId, teamMemberId, hardwareId and tankHardwareId.',
params: {
type: 'object',
required: ['customerId', 'teamMemberId', 'hardwareId', 'tankHardwareId'],
properties: {
customerId: { type: 'string', description: 'Customer ID' },
teamMemberId: { type: 'string', description: 'Team member ID' },
hardwareId: { type: 'string', description: 'Master hardwareId' },
tankHardwareId: { type: 'string', description: 'Tank hardwareId' }
}
},
body: {
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' }
}
},
},
handler : installationController.editTankDimensions
});
fastify.post( fastify.post(

Loading…
Cancel
Save