|
|
|
@ -5125,9 +5125,12 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
return reply.code(404).send({ message: "No support record found for this supportId" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Collect all hardwareIds (hardwareId + hardwareIds[])
|
|
|
|
|
// 2. Filter only unresolved issues
|
|
|
|
|
const unresolvedIssues = (supportRecord.issues || []).filter(issue => issue.resolved === false);
|
|
|
|
|
|
|
|
|
|
// 3. Collect all hardwareIds (hardwareId + hardwareIds[] from unresolved issues)
|
|
|
|
|
const allHardwareIds = new Set();
|
|
|
|
|
for (const issue of supportRecord.issues) {
|
|
|
|
|
for (const issue of unresolvedIssues) {
|
|
|
|
|
if (issue.hardwareId) allHardwareIds.add(issue.hardwareId.trim().toLowerCase());
|
|
|
|
|
if (Array.isArray(issue.hardwareIds)) {
|
|
|
|
|
issue.hardwareIds.forEach(id => {
|
|
|
|
@ -5137,12 +5140,12 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (allHardwareIds.size === 0) {
|
|
|
|
|
return reply.code(404).send({ message: "No hardware IDs found in issues" });
|
|
|
|
|
return reply.code(404).send({ message: "No unresolved hardware IDs found in issues" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const hardwareIdsArray = Array.from(allHardwareIds);
|
|
|
|
|
|
|
|
|
|
// 3. Find disconnected insensors using connected_to match (normalize connected_to)
|
|
|
|
|
// 4. Find disconnected insensors using connected_to match
|
|
|
|
|
const disconnectedSensors = await Insensors.find({
|
|
|
|
|
connected_to: { $in: hardwareIdsArray }
|
|
|
|
|
}).lean();
|
|
|
|
@ -5151,11 +5154,11 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
return reply.code(404).send({ message: "No disconnected issues found" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4. Get unique customerIds from disconnected sensors
|
|
|
|
|
// 5. Get unique customerIds from disconnected sensors
|
|
|
|
|
const customerIds = [...new Set(disconnectedSensors.map(s => s.customerId))];
|
|
|
|
|
const customers = await User.find({ customerId: { $in: customerIds } }).lean();
|
|
|
|
|
|
|
|
|
|
// 5. For each customer, calculate total unique hardwareIds involved in their disconnected sensors
|
|
|
|
|
// 6. For each customer, calculate total unique hardwareIds involved in their disconnected sensors
|
|
|
|
|
const customerHardwareMap = {};
|
|
|
|
|
|
|
|
|
|
for (const sensor of disconnectedSensors) {
|
|
|
|
@ -5167,7 +5170,7 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
const sensorHw = sensor.tankhardwareId?.trim().toLowerCase();
|
|
|
|
|
const sensorConnected = sensor.connected_to?.trim().toLowerCase();
|
|
|
|
|
|
|
|
|
|
for (const issue of supportRecord.issues) {
|
|
|
|
|
for (const issue of unresolvedIssues) {
|
|
|
|
|
const issueHw = issue.hardwareId?.trim().toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
@ -5188,15 +5191,15 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6. Build final response
|
|
|
|
|
// 7. Build final response
|
|
|
|
|
const response = [];
|
|
|
|
|
|
|
|
|
|
for (const user of customers) {
|
|
|
|
|
const custId = user.customerId;
|
|
|
|
|
const hardwareIdSet = customerHardwareMap[custId] || new Set();
|
|
|
|
|
|
|
|
|
|
// Extract latest issue-specific lastTicketRaisedAt
|
|
|
|
|
const relatedIssues = supportRecord.issues.filter(issue => {
|
|
|
|
|
// Extract latest unresolved issue-specific lastTicketRaisedAt
|
|
|
|
|
const relatedIssues = unresolvedIssues.filter(issue => {
|
|
|
|
|
const issueHw = issue.hardwareId?.trim().toLowerCase();
|
|
|
|
|
const hardwareIds = issue.hardwareIds?.map(id => id?.trim().toLowerCase()) || [];
|
|
|
|
|
const allIds = [issueHw, ...hardwareIds];
|
|
|
|
@ -5269,6 +5272,8 @@ exports.getDisconnectedCustomerDetails = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDisconnectedCustomerDetailsByTeamMemberId = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { support_teamMemberId } = req.params;
|
|
|
|
|