Fix Bug | relocate data | set basic filter
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user