ashok 3 months ago
commit 25d8bbafb1

@ -3095,6 +3095,128 @@ exports.getWaitingMasterSlaveSummary = async (req, reply) => {
} }
}; };
exports.getMasterWithSlaves = async (req, reply) => {
try {
const { installationId, customerId, hardwareId } = req.params;
if (!installationId || !customerId || !hardwareId) {
return reply.code(400).send({ success: false, message: "installationId, customerId, and hardwareId are required" });
}
// Find order
const order = await Order.findOne({ installationId, customerId }).lean();
if (!order) {
return reply.code(404).send({ success: false, message: "Order not found" });
}
// Find master device in Insensors
const master = await Insensors.findOne({
hardwareId,
customerId,
}).lean();
if (!master) {
return reply.code(404).send({ success: false, message: "Master device not found in Insensors" });
}
// // Find slaves connected to this master
// const slaves = await Insensors.find({
// connected_to: hardwareId,
// customerId,
// type: 'slave'
// }).lean();
return reply.send({
success: true,
master,
});
} catch (error) {
console.error("Error fetching master and slaves:", error);
return reply.code(500).send({ success: false, message: "Internal server error" });
}
};
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 {
const { customerId } = req.params; const { customerId } = req.params;

@ -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(
@ -593,6 +621,81 @@ fastify.post(
handler: installationController.getMasterSlaveSummary, handler: installationController.getMasterSlaveSummary,
}); });
fastify.get('/api/master-with-slaves/:installationId/:customerId/:hardwareId', {
schema: {
tags: ['Installation'],
summary: 'Get Individual master device and its connected slaves',
description: 'Fetch a master device from Insensors by hardwareId and list all connected slave devices for the same customer and installation.',
params: {
type: 'object',
required: ['installationId', 'customerId', 'hardwareId'],
properties: {
installationId: { type: 'string', description: 'Installation ID from Order' },
customerId: { type: 'string', description: 'Customer ID' },
hardwareId: { type: 'string', description: 'Master hardwareId' },
}
},
// response: {
// 200: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// master: {
// type: 'object',
// description: 'Master device details',
// properties: {
// _id: { type: 'string' },
// hardwareId: { type: 'string' },
// customerId: { type: 'string' },
// type: { type: 'string' },
// // Add other master fields as needed...
// }
// },
// slaves: {
// type: 'array',
// description: 'List of connected slave devices',
// items: {
// type: 'object',
// properties: {
// _id: { type: 'string' },
// hardwareId: { type: 'string' },
// connected_to: { type: 'string' },
// customerId: { type: 'string' },
// type: { type: 'string' },
// // Add other slave fields as needed...
// }
// }
// }
// }
// },
// 400: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// },
// 404: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// },
// 500: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// }
// }
},
handler: installationController.getMasterWithSlaves,
});
fastify.get("/api/getwaitingmasterlistwithslaves/:customerId", { fastify.get("/api/getwaitingmasterlistwithslaves/:customerId", {
schema: { schema: {
description: "Get waiting manager masrter connected slave data with full info", description: "Get waiting manager masrter connected slave data with full info",

Loading…
Cancel
Save