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
+21 -4
View File
@@ -24,7 +24,8 @@ module.exports.deviceRegistration = [
deviceId: device.id,
status: 0,
registerDate: new Date(),
userId: req.user_id
userId: req.user_id,
IMEI: req.body.IMEI
}
const newRequest = await InstalledDevice.create(data);
device.status = 1;
@@ -53,7 +54,16 @@ module.exports.getAllForUser = async (req, res) => {
page = req.query.page
page = page * rows - rows
}
const data = await InstalledDevice.find({ userId: req.user_id }).skip(page).limit(rows).sort({ created_at: -1 }).populate('deviceId')
const search = req.query?.search ? req.query.search : ""
const data = await InstalledDevice.find({
userId: req.user_id,
$or: [
{ IMEI: { $regex: search, $options: 'i' } },
],
}).skip(page).limit(rows).sort({ created_at: -1 }).populate('deviceId')
const total = Math.ceil((await InstalledDevice.countDocuments({ userId: req.user_id })))
res.status(200).json({ data, total })
@@ -78,7 +88,13 @@ module.exports.getAllForAdmin = async (req, res) => {
page = req.query.page
page = page * rows - rows
}
const data = await InstalledDevice.find({}).sort({ status: 1 }).skip(page).limit(rows)
const search = req.query?.search ? req.query.search : ""
const data = await InstalledDevice.find({
$or: [
{ IMEI: { $regex: search, $options: 'i' } },
]
}).sort({ status: 1 }).skip(page).limit(rows)
.populate('deviceId')
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
@@ -108,12 +124,13 @@ module.exports.updateInstalled = [
device.status = 1;
user.walletBalance = device.profit
user.walletBalance = device.profit
user.dollarBalance = device.dollarProfit
user.score = device.score
await Score.create({
title:"ثبت دستگاه",
deviceId: device.id,
score: device.score,
userId: installedDevice.userId
+9 -1
View File
@@ -24,8 +24,16 @@ module.exports.getAll = async (req, res) => {
page = req.query.page
page = page * rows - rows
}
const search = req.query?.search ? req.query.search : ""
const score = await Score.find({ userId: req.user_id }).skip(page).limit(rows);
const score = await Score.find({
userId: req.user_id,
$or: [
{ title: { $regex: search, $options: 'i' } },
{ score: { $regex: search, $options: 'i' } },
],
}).skip(page).limit(rows);
const total = Math.ceil((await Score.countDocuments({ userId: req.user_id })))
const user = await User.findById(req.user_id).select('score')
+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 })
}
+1
View File
@@ -5,6 +5,7 @@ const InstalledDeviceSchema = mongoose.Schema({
type: String,
ref: "Device"
},
IMEI:String,
status: {
type: Number,
enum: [
+1
View File
@@ -5,6 +5,7 @@ const ScoreSchema = mongoose.Schema({
type: String,
ref: 'Device'
},
title:String,
score: {
type: Number,
min: 0