search in user first name or last name

This commit is contained in:
2025-12-25 12:48:56 +03:30
parent a1f099a936
commit 883c1458a0
+18 -15
View File
@@ -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 } },