ashok 3 months ago
commit 1a1a966a8e

@ -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;

@ -421,6 +421,69 @@ module.exports = function (fastify, opts, next) {
},
handler: installationController.masterConnectedSlaveList,
});
fastify.post(
'/api/update-status/:connectedTo/:teamMemberId/:customerId',
{
schema: {
description: 'Update work_status in Order and set product_status to complete for master and connected slaves',
summary: 'Update work_status in Order and set product_status to complete for master and connected slaves',
tags: ['Installation'],
params: {
type: 'object',
required: ['connectedTo', 'teamMemberId', 'customerId'],
properties: {
connectedTo: { type: 'string', description: 'Master hardwareId' },
teamMemberId: { type: 'string', description: 'Team member ID' },
customerId: { type: 'string', description: 'Customer ID' }
}
},
body: {
type: 'object',
required: ['work_status'],
properties: {
work_status: {
type: 'string',
enum: ['active', 'pending', 'complete','waiting'], // update enum based on what your Orders schema allows
description: 'New work status to set in master_connections'
}
}
},
// response: {
// 200: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' },
// orderMatchedCount: { type: 'integer' },
// orderModifiedCount: { type: 'integer' },
// masterModifiedCount: { type: 'integer' },
// slaveModifiedCount: { type: 'integer' }
// }
// },
// 400: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// },
// 500: {
// type: 'object',
// properties: {
// success: { type: 'boolean' },
// message: { type: 'string' }
// }
// }
// }
},
handler: installationController.updateWorkStatusAndProductStatus
}
);
fastify.post(
'/api/insensors/media/:customerId',
{

Loading…
Cancel
Save