search in user first name or last name
This commit is contained in:
@@ -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 } },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user