Fix Bug | relocate data | set basic filter

This commit is contained in:
Mr Swift
2024-08-11 18:50:30 +03:30
parent 9769e2cf63
commit ad04de7832
5 changed files with 42 additions and 6 deletions
+10 -1
View File
@@ -58,8 +58,17 @@ module.exports.getAllForUser = async (req, res) => {
page = req.query.page
page = page * rows - rows
}
const search = req.query?.search ? req.query.search : ""
const data = await Withdraw.find({ userId: req.user_id }).skip(page).limit(rows).sort({ created_at: -1 });
const data = await Withdraw.find({
userId: req.user_id,
$or: [
{ amount: { $regex: search, $options: 'i' } },
{ dollarAmount: { $regex: search, $options: 'i' } },
{ trackingNumber: { $regex: search, $options: 'i' } },
],
}).skip(page).limit(rows).sort({ created_at: -1 });
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
res.status(201).json({ data, total })
}