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
|
||||
|
||||
@@ -24,17 +24,28 @@ module.exports.getAll = async (req, res) => {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
}
|
||||
// const search = req.query?.search ? req.query.search : ""
|
||||
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 score = await Score.find({
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
// $or: [
|
||||
// { title: { $regex: search } },
|
||||
// { score: { $regex: search } },
|
||||
// ],
|
||||
}).skip(page).limit(rows);
|
||||
const total = Math.ceil((await Score.countDocuments({ userId: req.user_id })))
|
||||
}
|
||||
|
||||
if(search){
|
||||
filter.$or = [
|
||||
{ title: { $regex: search } },
|
||||
{ score: search },
|
||||
]
|
||||
}
|
||||
|
||||
const score = await Score.find(filter).skip(page).limit(rows).sort(sort);
|
||||
const total = Math.ceil((await Score.countDocuments(filter)))
|
||||
|
||||
const user = await User.findById(req.user_id).select('score')
|
||||
res.status(200).json({ data: score, score: user.score, total })
|
||||
|
||||
@@ -66,18 +66,29 @@ module.exports.getAllForUser = async (req, res) => {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
}
|
||||
// const search = req.query?.search ? req.query.search : 0
|
||||
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 data = await Withdraw.find({
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
// $or: [
|
||||
// { amount: { $regex: search } },
|
||||
// { dollarAmount: { $regex: search } },
|
||||
// { trackingNumber: { $regex: search } },
|
||||
// ],
|
||||
}).skip(page).limit(rows).sort({ created_at: -1 });
|
||||
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
|
||||
}
|
||||
|
||||
if(search){
|
||||
filter.$or = [
|
||||
{ amount: search },
|
||||
{ dollarAmount: search },
|
||||
{ trackingNumber: { $regex: search } },
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort);
|
||||
const total = Math.ceil((await Withdraw.countDocuments(filter)))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user