Fix Bug | relocate data | set basic filter
This commit is contained in:
@@ -24,7 +24,8 @@ module.exports.deviceRegistration = [
|
|||||||
deviceId: device.id,
|
deviceId: device.id,
|
||||||
status: 0,
|
status: 0,
|
||||||
registerDate: new Date(),
|
registerDate: new Date(),
|
||||||
userId: req.user_id
|
userId: req.user_id,
|
||||||
|
IMEI: req.body.IMEI
|
||||||
}
|
}
|
||||||
const newRequest = await InstalledDevice.create(data);
|
const newRequest = await InstalledDevice.create(data);
|
||||||
device.status = 1;
|
device.status = 1;
|
||||||
@@ -53,7 +54,16 @@ module.exports.getAllForUser = async (req, res) => {
|
|||||||
page = req.query.page
|
page = req.query.page
|
||||||
page = page * rows - rows
|
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 })))
|
const total = Math.ceil((await InstalledDevice.countDocuments({ userId: req.user_id })))
|
||||||
res.status(200).json({ data, total })
|
res.status(200).json({ data, total })
|
||||||
@@ -78,7 +88,13 @@ module.exports.getAllForAdmin = async (req, res) => {
|
|||||||
page = req.query.page
|
page = req.query.page
|
||||||
page = page * rows - rows
|
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('deviceId')
|
||||||
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
|
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
|
||||||
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
|
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
|
||||||
@@ -114,6 +130,7 @@ module.exports.updateInstalled = [
|
|||||||
|
|
||||||
|
|
||||||
await Score.create({
|
await Score.create({
|
||||||
|
title:"ثبت دستگاه",
|
||||||
deviceId: device.id,
|
deviceId: device.id,
|
||||||
score: device.score,
|
score: device.score,
|
||||||
userId: installedDevice.userId
|
userId: installedDevice.userId
|
||||||
|
|||||||
@@ -24,8 +24,16 @@ 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 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 total = Math.ceil((await Score.countDocuments({ userId: req.user_id })))
|
||||||
|
|
||||||
const user = await User.findById(req.user_id).select('score')
|
const user = await User.findById(req.user_id).select('score')
|
||||||
|
|||||||
@@ -58,8 +58,17 @@ 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 : ""
|
||||||
|
|
||||||
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 })))
|
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
|
||||||
res.status(201).json({ data, total })
|
res.status(201).json({ data, total })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const InstalledDeviceSchema = mongoose.Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
ref: "Device"
|
ref: "Device"
|
||||||
},
|
},
|
||||||
|
IMEI:String,
|
||||||
status: {
|
status: {
|
||||||
type: Number,
|
type: Number,
|
||||||
enum: [
|
enum: [
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const ScoreSchema = mongoose.Schema({
|
|||||||
type: String,
|
type: String,
|
||||||
ref: 'Device'
|
ref: 'Device'
|
||||||
},
|
},
|
||||||
|
title:String,
|
||||||
score: {
|
score: {
|
||||||
type: Number,
|
type: Number,
|
||||||
min: 0
|
min: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user