Fix search bug
This commit is contained in:
@@ -60,17 +60,25 @@ module.exports.getAllForUser = async (req, res) => {
|
||||
page = page * rows - rows
|
||||
}
|
||||
|
||||
const search = req.query?.search ? req.query.search : ""
|
||||
|
||||
|
||||
const data = await InstalledDevice.find({
|
||||
const search = req.query?.search ? req.query.search : null
|
||||
let sort
|
||||
if(req.query?.sort){
|
||||
sort= req.query?.sort
|
||||
}else{
|
||||
sort= { created_at: -1 }
|
||||
}
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
$or: [
|
||||
}
|
||||
if(search){
|
||||
filter.$or = [
|
||||
{ IMEI: { $regex: search } },
|
||||
],
|
||||
}).skip(page).limit(rows).sort({ created_at: -1 }).populate('deviceId')
|
||||
]
|
||||
}
|
||||
|
||||
const total = Math.ceil((await InstalledDevice.countDocuments({ userId: req.user_id })))
|
||||
const data = await InstalledDevice.find(filter).skip(page).limit(rows).sort(sort).populate('deviceId')
|
||||
|
||||
const total = Math.ceil((await InstalledDevice.countDocuments(filter)))
|
||||
res.status(200).json({ data, total })
|
||||
|
||||
}
|
||||
@@ -124,7 +132,7 @@ module.exports.updateInstalled = [
|
||||
installedDevice.installationDate = new Date();
|
||||
|
||||
device.status = 1;
|
||||
|
||||
|
||||
user.walletBalance += device.profit
|
||||
user.dollarBalance += device.dollarProfit
|
||||
user.score = device.score
|
||||
|
||||
Reference in New Issue
Block a user