|
|
|
@ -1935,6 +1935,52 @@ return {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateWorkStatusAndProductStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { connectedTo, teamMemberId, customerId } = req.params;
|
|
|
|
|
const { work_status } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!connectedTo || !teamMemberId || !customerId) {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "connectedTo, teamMemberId, and customerId are required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!work_status) {
|
|
|
|
|
return reply.status(400).send({ success: false, message: "work_status is required in body" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 1: Update work_status in Order schema
|
|
|
|
|
const orderUpdate = await Order.updateOne(
|
|
|
|
|
{ customerId, "master_connections.hardwareId": connectedTo },
|
|
|
|
|
{ $set: { "master_connections.$.work_status": work_status } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Step 2: Update master product_status
|
|
|
|
|
const masterUpdate = await Insensors.updateOne(
|
|
|
|
|
{ hardwareId: connectedTo, type: 'master', customerId },
|
|
|
|
|
{ $set: { product_status: 'complete', team_member_support_gsm_last_check_time: new Date().toISOString() } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Step 3: Update all connected slaves product_status
|
|
|
|
|
const slaveUpdate = await Insensors.updateMany(
|
|
|
|
|
{ connected_to: connectedTo, type: 'slave', customerId },
|
|
|
|
|
{ $set: { product_status: 'complete', team_member_support_lora_last_check_time: new Date().toISOString() } }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
success: true,
|
|
|
|
|
message: 'Work status and product_status updated successfully',
|
|
|
|
|
orderMatchedCount: orderUpdate.matchedCount,
|
|
|
|
|
orderModifiedCount: orderUpdate.modifiedCount,
|
|
|
|
|
masterModifiedCount: masterUpdate.modifiedCount,
|
|
|
|
|
slaveModifiedCount: slaveUpdate.modifiedCount
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error updating work_status and product_status:', error);
|
|
|
|
|
return reply.status(500).send({ success: false, message: 'Internal Server Error' });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exports.addMediaToInsensor = async (req, reply) => {
|
|
|
|
|
// try {
|
|
|
|
|
// const { hardwareId, customerId, type } = req.params;
|
|
|
|
|