From 883c1458a0e7a7934493edad7bd7d275e12c0ed8 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 25 Dec 2025 12:48:56 +0330 Subject: [PATCH] search in user first name or last name --- server/controllers/GPS.InstalledDevice.js | 33 ++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/server/controllers/GPS.InstalledDevice.js b/server/controllers/GPS.InstalledDevice.js index 18d7a0f..20e6a09 100644 --- a/server/controllers/GPS.InstalledDevice.js +++ b/server/controllers/GPS.InstalledDevice.js @@ -197,11 +197,11 @@ module.exports.getAllForAdmin = async (req, res) => { } } - if (search) { - match.$or = [ - { IMEI: { $regex: search, $options: 'i' } } - ] - } + // if (search) { + // match.$or = [ + // { IMEI: { $regex: search, $options: 'i' } }, + // ] + // } const pipeline = [ { $match: match }, @@ -216,16 +216,7 @@ module.exports.getAllForAdmin = async (req, res) => { }, { $unwind: { path: '$deviceId', preserveNullAndEmptyArrays: true } }, - ...(search - ? [{ - $match: { - $or: [ - { 'deviceId.model': { $regex: search, $options: 'i' } }, - { IMEI: { $regex: search, $options: 'i' } } - ] - } - }] - : []), + { $lookup: { @@ -260,6 +251,18 @@ module.exports.getAllForAdmin = async (req, res) => { } }, { $unwind: { path: '$userId', preserveNullAndEmptyArrays: true } }, + ...(search + ? [{ + $match: { + $or: [ + { 'deviceId.model': { $regex: search, $options: 'i' } }, + { IMEI: { $regex: search, $options: 'i' } }, + { 'userId.first_name': { $regex: search, $options: 'i' } }, + { 'userId.last_name': { $regex: search, $options: 'i' } } + ] + } + }] + : []), { $sort: { created_at: -1 } },