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) {
|
// if (search) {
|
||||||
match.$or = [
|
// match.$or = [
|
||||||
{ IMEI: { $regex: search, $options: 'i' } }
|
// { IMEI: { $regex: search, $options: 'i' } },
|
||||||
]
|
// ]
|
||||||
}
|
// }
|
||||||
|
|
||||||
const pipeline = [
|
const pipeline = [
|
||||||
{ $match: match },
|
{ $match: match },
|
||||||
@@ -216,16 +216,7 @@ module.exports.getAllForAdmin = async (req, res) => {
|
|||||||
},
|
},
|
||||||
{ $unwind: { path: '$deviceId', preserveNullAndEmptyArrays: true } },
|
{ $unwind: { path: '$deviceId', preserveNullAndEmptyArrays: true } },
|
||||||
|
|
||||||
...(search
|
|
||||||
? [{
|
|
||||||
$match: {
|
|
||||||
$or: [
|
|
||||||
{ 'deviceId.model': { $regex: search, $options: 'i' } },
|
|
||||||
{ IMEI: { $regex: search, $options: 'i' } }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
: []),
|
|
||||||
|
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
@@ -260,6 +251,18 @@ module.exports.getAllForAdmin = async (req, res) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ $unwind: { path: '$userId', preserveNullAndEmptyArrays: true } },
|
{ $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 } },
|
{ $sort: { created_at: -1 } },
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user