status change to inprogress store

master^2
Bhaskar 3 months ago
parent 6883eb8b46
commit 17236717b9

@ -10131,7 +10131,6 @@ exports.sendToStoreHardwareList = async (req, reply) => {
if (!allRelatedSensors.length) return reply.code(404).send({ message: "No sensors found" });
// 🔍 Filter orders by optional storeId
let orders = [];
if (storeId) {
orders = await Order.find({ customerId, storeId }).lean();
@ -10177,10 +10176,17 @@ exports.sendToStoreHardwareList = async (req, reply) => {
}
await Insensors.updateOne(
{ hardwareId: master.hardwareId },
{ $set: { connected_status: gsmConnected ? "connected" : "disconnected" } }
{ hardwareId: master.hardwareId.trim() },
{
$set: {
connected_status: gsmConnected ? "connected" : "disconnected",
outDoor_status: "inprogress store"
}
}
);
const updatedMaster = await Insensors.findOne({ hardwareId: master.hardwareId.trim() }).lean();
const slaveDetails = await Promise.all(slaves.map(async (slave) => {
const slaveHardwareId = slave.tankhardwareId?.trim();
const matchedTank = latestIotData?.tanks?.find(tank => tank.tankhardwareId === slaveHardwareId);
@ -10193,9 +10199,16 @@ exports.sendToStoreHardwareList = async (req, reply) => {
await Insensors.updateOne(
{ tankhardwareId: slaveHardwareId },
{ $set: { connected_status: loraConnected ? "connected" : "disconnected" } }
{
$set: {
connected_status: loraConnected ? "connected" : "disconnected",
outDoor_status: "inprogress store"
}
}
);
const updatedSlave = await Insensors.findOne({ tankhardwareId: slaveHardwareId }).lean();
const tankInfo = await Tank.findOne({
$or: [
{ hardwareId: slaveHardwareId },
@ -10203,31 +10216,24 @@ exports.sendToStoreHardwareList = async (req, reply) => {
]
}).lean();
const slaveComments = (support.comments || []).filter(
comment => comment.hardwareId === slave.hardwareId && comment.customerId === customerId
).map(c => ({
text: c.text,
commentsTime: c.createdAt ? moment(c.createdAt).tz("Asia/Kolkata").format("DD-MM-YYYY HH:mm") : null
}));
return {
hardwareId: slave.tankhardwareId,
tankName: slave.tankName || "",
location: slave.tankLocation || "",
connected_status: loraConnected ? "connected" : "disconnected",
connected_to: slave.connected_to || "",
gsm_last_check_time: slave.gsm_last_check_time || null,
gsm_last_disconnect_time: slave.gsm_last_disconnect_time || null,
lora_last_disconnect_time: slave.lora_last_disconnect_time || null,
connected_gsm_date: slave.connected_gsm_date || "",
connected_gsm_time: slave.connected_gsm_time || "",
connected_lora_date: slave.connected_lora_date || "",
connected_lora_time: slave.connected_lora_time || "",
support_lora_last_check_time: slave.support_lora_last_check_time || null,
hardwareId: updatedSlave.tankhardwareId,
tankName: updatedSlave.tankName || "",
location: updatedSlave.tankLocation || "",
connected_status: updatedSlave.connected_status,
connected_to: updatedSlave.connected_to || "",
gsm_last_check_time: updatedSlave.gsm_last_check_time || null,
gsm_last_disconnect_time: updatedSlave.gsm_last_disconnect_time || null,
lora_last_disconnect_time: updatedSlave.lora_last_disconnect_time || null,
connected_gsm_date: updatedSlave.connected_gsm_date || "",
connected_gsm_time: updatedSlave.connected_gsm_time || "",
connected_lora_date: updatedSlave.connected_lora_date || "",
connected_lora_time: updatedSlave.connected_lora_time || "",
support_lora_last_check_time: updatedSlave.support_lora_last_check_time || null,
masterName: orderMap[master.hardwareId?.trim()]?.masterName || "",
type: "slave",
typeOfWater: tankInfo?.typeOfWater || "",
outDoor_status: slave.outDoor_status || "inprogress"
outDoor_status: updatedSlave.outDoor_status
};
}));
@ -10243,46 +10249,44 @@ exports.sendToStoreHardwareList = async (req, reply) => {
const issue = issueMap[master.hardwareId];
disconnectedIssues.push({
hardwareId: master.hardwareId,
hardwareId: updatedMaster.hardwareId,
masterName: orderDetails.masterName || "",
location: orderDetails.location || "",
type: "master",
connected_status: gsmConnected ? "connected" : "disconnected",
connected_status: updatedMaster.connected_status,
connected_slave_count: slaveDetails.length,
gsm_last_check_time: master.gsm_last_check_time || null,
gsm_last_disconnect_time: master.gsm_last_disconnect_time || null,
lora_last_disconnect_time: master.lora_last_disconnect_time || null,
connected_gsm_date: master.connected_gsm_date || "",
connected_gsm_time: master.connected_gsm_time || "",
connected_lora_date: master.connected_lora_date || "",
connected_lora_time: master.connected_lora_time || "",
support_gm_last_check_time: master.support_gsm_last_check_time || null,
gsm_last_check_time: updatedMaster.gsm_last_check_time || null,
gsm_last_disconnect_time: updatedMaster.gsm_last_disconnect_time || null,
lora_last_disconnect_time: updatedMaster.lora_last_disconnect_time || null,
connected_gsm_date: updatedMaster.connected_gsm_date || "",
connected_gsm_time: updatedMaster.connected_gsm_time || "",
connected_lora_date: updatedMaster.connected_lora_date || "",
connected_lora_time: updatedMaster.connected_lora_time || "",
support_gm_last_check_time: updatedMaster.support_gsm_last_check_time || null,
connected_slaves: slaveDetails,
comments: masterComments,
outDoor_status: master.outDoor_status || "inprogress",
outDoor_status: updatedMaster.outDoor_status,
movedAt: issue?.movedAt || null,
resolvedAt: issue?.resolvedAt || null,
category: issue?.category || "Uncategorized",
hardwareList: master.hardwareList || {},
hardwareList: updatedMaster.hardwareList || {},
assignedTo: issue?.assignedTo || null
});
}
// ✅ Step: Update storeId in Orders where matching master_connections.hardwareId
// ✅ Step: Update storeId and type in Orders where matching master_connections.hardwareId
const updatedHardwareIds = disconnectedIssues.map(item => item.hardwareId);
await Order.updateMany(
{
customerId,
"master_connections.hardwareId": { $in: updatedHardwareIds }
},
{
$set: {
storeId,
type: type // Fallback if type is not passed
}
}
);
const updatedHardwareIds = disconnectedIssues.map(item => item.hardwareId);
await Order.updateMany(
{
customerId,
"master_connections.hardwareId": { $in: updatedHardwareIds }
},
{
$set: {
storeId,
type: type
}
}
);
return reply.send({
status_code: 200,
@ -10300,6 +10304,7 @@ await Order.updateMany(
};
exports.updateHardwareList = async (req, reply) => {
try {
const { supportId, customerId, hardwareId } = req.params;

@ -617,6 +617,11 @@ team_member_support_gsm_last_check_time : { type: String, default: null },
team_member_support_lora_last_check_time : { type: String, default: null },
lora_last_check_time : { type: String, default: null },
gsm_last_disconnect_time : { type: String, default: null },
outDoor_status: {
type: String,
enum: ['inprogress', 'inprogress store','ready to pick up', 'dispatched'],
default: 'inprogress' // optional: set default
},
lora_last_disconnect_time : { type: String, default: null },
hardwareList: {
type: [
@ -647,11 +652,7 @@ lora_last_disconnect_time : { type: String, default: null },
data_sending: { result: String },
connected_slave_count: {type : String},
lastTicketRaisedAt: { type: String },
outDoor_status: {
type: String,
enum: ['inprogress', 'ready to pick up', 'dispatched'],
default: 'inprogress' // optional: set default
},
// hardwareList: {
// type: Map,
// of: Number,

Loading…
Cancel
Save