Fix search bug
This commit is contained in:
@@ -60,17 +60,25 @@ module.exports.getAllForUser = async (req, res) => {
|
|||||||
page = page * rows - rows
|
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){
|
||||||
const data = await InstalledDevice.find({
|
sort= req.query?.sort
|
||||||
|
}else{
|
||||||
|
sort= { created_at: -1 }
|
||||||
|
}
|
||||||
|
const filter = {
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
$or: [
|
}
|
||||||
|
if(search){
|
||||||
|
filter.$or = [
|
||||||
{ IMEI: { $regex: search } },
|
{ 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 })
|
res.status(200).json({ data, total })
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,7 +132,7 @@ module.exports.updateInstalled = [
|
|||||||
installedDevice.installationDate = new Date();
|
installedDevice.installationDate = new Date();
|
||||||
|
|
||||||
device.status = 1;
|
device.status = 1;
|
||||||
|
|
||||||
user.walletBalance += device.profit
|
user.walletBalance += device.profit
|
||||||
user.dollarBalance += device.dollarProfit
|
user.dollarBalance += device.dollarProfit
|
||||||
user.score = device.score
|
user.score = device.score
|
||||||
|
|||||||
@@ -24,17 +24,28 @@ module.exports.getAll = async (req, res) => {
|
|||||||
page = req.query.page
|
page = req.query.page
|
||||||
page = page * rows - rows
|
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,
|
userId: req.user_id,
|
||||||
// $or: [
|
}
|
||||||
// { title: { $regex: search } },
|
|
||||||
// { score: { $regex: search } },
|
if(search){
|
||||||
// ],
|
filter.$or = [
|
||||||
}).skip(page).limit(rows);
|
{ title: { $regex: search } },
|
||||||
const total = Math.ceil((await Score.countDocuments({ userId: req.user_id })))
|
{ 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')
|
const user = await User.findById(req.user_id).select('score')
|
||||||
res.status(200).json({ data: score, score: user.score, total })
|
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 = req.query.page
|
||||||
page = page * rows - rows
|
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 filter = {
|
||||||
const data = await Withdraw.find({
|
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
// $or: [
|
}
|
||||||
// { amount: { $regex: search } },
|
|
||||||
// { dollarAmount: { $regex: search } },
|
if(search){
|
||||||
// { trackingNumber: { $regex: search } },
|
filter.$or = [
|
||||||
// ],
|
{ amount: search },
|
||||||
}).skip(page).limit(rows).sort({ created_at: -1 });
|
{ dollarAmount: search },
|
||||||
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
|
{ 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 })
|
res.status(200).json({ data, total })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user